The JSON syntax is a subset of the JavaScript syntax.
JSON syntax is derived from JavaScript item notation syntax:
JSON information is written as name/value pairs (aka key/value pairs).
A name/value pair includes a field name (in double quotes), accompanied through a colon, followed through a value:
Example
"name":"John"
The JSON formation is almost similar to JavaScript objects.
In JSON, keys should be strings, and written with double quotes:
JSON
{"name":"John"}
In JavaScript, keys might be strings, numbers, or identifier names:
JavaScript
{name:"John"}
JSON Values
In JSON, values should be one of the following data types:
In JavaScript, values can be all of the above, plus any other valid JavaScript expression, including:
In JSON, string value must be written with double quotes:
JSON
{"name":"John"}
In JavaScript, you can note string values with double and single quotes:
JavaScript
{name:'John'}
A simple Example is Given Below;
{ "book": [ { "id": "01", "language": "Java", "edition": "third", "author": "Herbert Schildt" }, { "id": "07", "language": "C++", "edition": "second", "author": "E.Balagurusamy" } ] }
JSON hold up the following two data structures −
JavaScript Array As JSON
A similar method of JavaScript objects can be written as JSON, JavaScript arrays can also be written as JSON.
You will get to learn more about objects and arrays in this tutorial after some time.
JSON Files