Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

JSON — parsing and serializing data

JSON is JavaScript’s built-in object for reading and writing JSON text. JSON.parse creates values from text, while JSON.stringify serializes values, but does not preserve every JavaScript type or object structure.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

JSON.parse(text[, reviver])
JSON.stringify(value[, replacer[, space]])

JSON is a built-in ECMAScript object, not a constructor or function: do not use new JSON() or JSON(). The JSON format describes objects, arrays, strings, numbers, booleans, and null. It requires double quotes for property names and strings; comments and trailing commas are not allowed.

JSON.parse(text, reviver) reads text; invalid syntax causes a SyntaxError. The optional reviver transforms values from nested elements toward the root; returning undefined deletes a property. Successful parsing does not validate an expected data schema, and large integers may lose precision as Number values.

JSON.stringify(value, replacer, space) returns text or undefined. replacer can be a function transforming values or an array of names selecting object properties; space controls indentation. For non-array objects, the default is to serialize own enumerable string-keyed properties. For arrays, values are read at indices 0 through length - 1, even if the indexed properties are inherited or non-enumerable. Extra named properties that are not indices are ignored, even if enumerable. A toJSON method, if present, can change the representation.

Properties with undefined, function, or symbol values are omitted from objects, but such array elements become null. NaN and infinities also become null. Cycles and unconverted BigInt values cause a TypeError. Consequently, serializing and parsing again is not a general-purpose deep-copy technique.

This entry and example cover the core methods, not the complete set of newer extensions. The current specification draft also describes JSON.rawJSON and JSON.isRawJSON; check availability in your target environment before using them. A result in Node 24 does not establish browser support.

Examples

const text = '{"name":"Ada","scores":[3,5]}';
const data = JSON.parse(text);
data.scores.push(8);
console.log(JSON.stringify(data));
console.log(JSON.stringify({ missing: undefined, items: [undefined] }));

Result

{"name":"Ada","scores":[3,5,8]}
{"items":[null]}

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources