JSON
Published in
1 min readOct 17, 2018
Sometimes you need to convert a complex object into a string, and viceversa, while keeping in mind that the properties of objects are constantly removed and added: in order to avoid having to manually update them you can use JSON.
JSON (JavaScript Object Notation) is used to represent values and objects, and can be used to turn objects, arrays, strings, numbers, booleans, null’s, into strings, and to decode JSON files. Two important JSON methods are:
let json = JSON.stringify(value, replacer, spacer);
let value = JSON.parse(string, reviver);
Stringify turns an object into JSON, whereas parse decodes JSON into an object.
It’s important to note that:
- JSON doesn’t allow comments.
- JSON uses double quotes (“”).
- Circular references must be avoided (e.g. X referencing Y with Y referencing X).
- Any property that stores “undefined” is skipped.