JSON
suggest changeIntroduction
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write and easy for machines to parse and generate. It is important to realize that, in JavaScript, JSON is a string and not an object.
A basic overview can be found on the json.org website which also contains links to implementations of the standard in many different programming languages.
Syntax
- JSON.parse(input[, reviver])
- JSON.stringify(value[, replacer[, space]])
Parameter
| Parameter | Details |
|---|---|
| JSON.parse | Parse a JSON string |
| input(string) | JSON string to be parsed. |
| reviver(function) | Called for each parsed value, from the inside outward. It can replace or drop that value. |
| JSON.stringify | Serialize a serializable value |
| value | Any JavaScript value to serialize. It does not have to be a string. |
| replacer(function or array) | A function that transforms values, or an array of names to keep. |
| space(string or number) | A number inserts up to 10 spaces per level. A string uses its first 10 characters as the indent. |
Remarks
The JSON utility methods were first standardized in ECMAScript 5.1 §15.12.
The format was defined in RFC 4627 (July 2006), then RFC 7159, and the current RFC is RFC 8259. ECMA-404 is the ECMA edition.
To make these methods available in old browsers such as Internet Explorer 8, use Douglas Crockford’s json2.js.
JSON versus JavaScript literals
Parsing with a reviver function
Serializing and restoring class instances
Serializing with a replacer function