valueThe JavaScript value to convert (object, array, string, number, boolean, or null).
replacerOptional function (key, value) => …, or an array of property names to keep.
spaceOptional number or string for indentation (pretty-print). Often 2 or "\\t".
Watch outs
Special Cases
undefinedDropped on objects; becomes null in arrays.
DateBecomes an ISO-8601 string (via toJSON).
functions / SymbolOmitted on objects; null in arrays.
NaN / InfinitySerialized as null.
circular refsThrow TypeError — JSON has no cycles.
BigIntThrows unless you convert it first (for example to a string).
JSON Schema
Output Shape
What you stringify should match the JSON shape your API or JSON Schema expects. Stringify only writes text; schema tools validate after someone parses it again.
JSON
const user = { name: "Ada", age: 36 };
const text = JSON.stringify(user);
const again = JSON.parse(text);
// again matches { "type": "object", "properties": { "name": …, "age": … } }
Code
Examples
Use View Output for a quick result, or Try It Yourself to edit and run in the browser.
Example 1 — Basic Stringify
Turn an object into compact JSON text.
JSON
const user = {
name: "Ada",
age: 36,
active: true
};
const text = JSON.stringify(user);
console.log(text);
console.log(typeof text);