JSON syntax is a subset of 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:
This is simple to understand, and equals to the JavaScript statement:
JSON values can be:
JSON objects are written inside curly brackets,
Objects can contain multiple name/values pairs:
This is also simple to understand, and equals to the JavaScript statements:
JSON arrays are written inside square brackets.
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.
Your message has been sent to W3Schools.