Converts a JavaScript value to a JSON (JavaScript Object Notation) string.
stringify(value, replacer?, space?)
value
A JavaScript value, usually an object or array, to be converted.
replacer optional function(key, value)
A function that transforms the results.
space optional
A number or a string to add indentation to the returned JSON string. If a number, indicates the number of space characters to use as white space; this number is capped at 10 (if it is greater, the value is just 10). If a string, indicates the string used as white space (a maximum of 10 characters will be used).
A string representing the value.
Throws an error if the object contains a circular reference an exception is thrown during conversion.
JSON.stringify({ temperature: 20, humidity: 60, feel: "ok" })
`{"temperature":20,"humidity":60,"feel":"ok"}`
JSON.stringify({ temperature: 20, humidity: 60, feel: "ok" }, null, 2)
`{
"temperature": 20,
"humidity": 60,
"feel": "ok"
}`
let x = {}
x.a = x
JSON.stringify(x)
TypeError: circular reference