The JSON syntax is a subset of the JavaScript syntax
JSON syntax is a subset of the JavaScript object notation syntax:
JSON data is written as name/value pairs.
A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value:
JSON values can be:
JSON objects are written inside curly braces.
Just like in JavaScript, objects can contain multiple name/values pairs:
JSON arrays are written inside square brackets.
Just like in JavaScript, an array can contain multiple objects:
In the example above, the object "employees" is an array containing three objects. Each object is a record of a person (with a first name and a last name).
Because JSON uses JavaScript syntax, no extra software is needed to work with JSON within JavaScript.
With JavaScript you can create an array of objects and assign data to it like this:
The first entry in the JavaScript object array can be accessed like this:
The returned content will be:
The data can be modified like this:
In the next chapter you will learn how to convert a JSON text to a JavaScript object.