JSON Data Format
What is JSON
- JSON is a data interchange format. Used to pass data to the web browser, or exchange data with other language, API, or used as a software config file.
- JSON file is plain text file.
- JSON file has file name extension
.json
. - JSON format is based on JavaScript objects syntax, of object/array arbitrarily nested.
JSON Code Example
{ "name": "Joe", "alive": true, "age": 25, "address": { "street": "1st Street", "state": "Cali" }, "phone": [ { "type": "home", "number": "123 456 7890" }, { "type": "office", "number": "123 456 7890" } ], "children": [], "spouse": null }
Difference Between JavaScript Syntax vs JSON Syntax
JSON syntax is more strict than JavaScript object/array syntax.
Key must be double quoted
// good {"h":2} // bad // {h:2} // bad // {'h':2}
Does not allow extra comma at end
// good {"h":2} // bad // {"h":2,}
Does not allow semicolon at the end
// good {"h":2} // bad // {"h":2};
Does not allow undefined
JSON value does not allow undefined
.
(but null
is ok)
// good {"h":null} // bad // {"h":undefined}
Does not allow comment
JSON does not allow comment in JSON string or file. Some language may support it, some not.