Skip to content

Latest commit

 

History

History
42 lines (36 loc) · 1.01 KB

JSON.stringify-tips.md

File metadata and controls

42 lines (36 loc) · 1.01 KB

https://javascript.info/json

Acceptable value

  • Objects {...}
  • Arrays [...]
  • Primitives:
    • strings,
    • numbers,
    • boolean values true/false
    • null

The following value will be ignored:

  • Function properties(methods)
  • Symbolic properties
  • Properties that store undefined

For instance

let user = {
  sayHi() { // ignored
    alert("Hello");
  },
  [Symbol("id")]: 123, // ignored
  something: undefined // ignored
};

alert( JSON.stringify(user) ); // {} (empty object)

ATTENTION circular references will cause an error.

The full syntax of JSON.stringify is:

const json = JSON.stringify(value[, replacer, space])
Parameter meaning
value A value to encode
replacer Array of properties to encode or a mapping function function(key, value).
space Amount of space to use for formating