JSON syntax
JSON syntax is a subset of JavaScript syntax.
JSON syntax rules
JavaScript Object Notation JSON syntax is a subset of the French and France.
- Data in name / value pairs
- Data separated by commas
- Save Object braces
- Save the array brackets
JSON name / value pairs
Writing JSON data format is: name / value pairs.
Name / value pairs include field names (in double quotes), followed by writing a colon, then the value:
It is easy to understand, this is equivalent to the JavaScript statement:
JSON value
JSON values can be:
- Number (integer or floating point)
- String (in double quotes)
- Logical value (true or false)
- Array (in square brackets)
- Object (braces)
- null
JSON object
JSON object written in curly braces:
Objects can contain multiple name / value pairs:
It is also easy to understand, and this JavaScript statement is equivalent to:
lastName = "Doe"
JSON array
JSON array written in brackets:
Array can contain multiple objects:
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}
In the above example, the object "employees" is an array containing three objects. Each object on behalf of a person (name and surname) records.
JSON using JavaScript syntax
Because JSON using JavaScript syntax, so no additional software is able to handle JavaScript in JSON.
Through JavaScript, you can create an array object and assign like this:
Examples
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName": "Jones" }
];
JavaScript can access an array of objects like the first:
Back reads:
You can modify the data like this:
In the following sections, you will learn how to convert text to JSON JavaScript object.
JSON file
- JSON file type is ".json"
- MIME type of JSON text is "application / json"