JSON.stringify

Converts a JavaScript value to a JSON (JavaScript Object Notation) string.

Syntax

stringify(value, replacer?, space?)

Parameters

Return value

A string representing the value.

Throws an error if the object contains a circular reference an exception is thrown during conversion.

Examples

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

See also