Lesson 15

JSON

JSON (commonly pronounced Jason) stands for JavaScript Object Notation. It is a data format for representing the properties of a JavaScript object as a string.

In computing, there are often instances where you need to convert data from one format to another. For instance, if you consider a JavaScript object, you may want to convert it into a String so that:

  • You can send it across a network to another computer.
  • You can store it in a file.
  • You can use it with other JavaScript APIs that only support strings.

Conversely, you may eventually want to convert this string back into an object so that you can use it in your JavaScript application.

The process of converting an object into a string is referred to as serialization, while the ­process of converting it back is referred to as de-serialization.

In order to convert an object into a string, you need a data-format that specifies how the object should be mapped to a character string—for instance, how do you denote the ­properties and values of an object, and how do you encode the various data types such as numbers and arrays?

Historically most data formats have been binary: This meant that it was not possible for a human to read the formatted data and gain an understanding of its underlying structure or meaning. Typically, data was converted to and from the binary format using a proprietary algorithm.

In recent years, there has been a move toward plain-text data formats. The most notable example is XML, which uses ...

Get HTML5, JavaScript, and jQuery 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.