JSON is the text format for saving and transmitting objects. JSON.stringify(value, replacer, indent) serializes and JSON.parse(text, reviver) restores. Keys need double quotes; comments, trailing commas and cycles (a TypeError) are not allowed. undefined and functions vanish, NaN becomes null, a Map becomes {}, and a Date becomes a string through its toJSON() method, which any object can define.
JSON.parse() also turns every number into a double, silently rounding 64-bit IDs. ECMAScript 2026 fixes both directions: the reviver receives a third context argument whose source holds the original text of each primitive, and JSON.rawJSON(text) wraps primitive JSON text in a frozen object that JSON.stringify() writes verbatim.
const order = { id: 7, placed: new Date(0), tags: new Map(), note: undefined, total: NaN };
console.log(JSON.stringify(order));
const text = '{"id": 12345678901234567890, "price": 19.90}';
console.log(JSON.parse(text).id); // rounded to a double
const data = JSON.parse(text, (key, value, context) =>
Number.isInteger(value) && !Number.isSafeInteger(value) ? BigInt(context.source) : value);
console.log(data.id, JSON.stringify(data, (key, value) =>
typeof value === "bigint" ? JSON.rawJSON(String(value)) : value));{"id":7,"placed":"1970-01-01T00:00:00.000Z","tags":{},"total":null}
12345678901234567000
12345678901234567890n {"id":12345678901234567890,"price":19.9}JSON.rawJSON() has been Baseline since March 2025; core-js 25,536 polyfills the reviver context for older runtimes.