Which method converts a JavaScript value to a JSON string?

The story behind the answer

The method that converts a JavaScript value to a JSON string is `JSON.stringify()`. It produces text in JSON notation, making JavaScript data suitable for storage, logging, or transmission across an API boundary. For example, `JSON.stringify({x: 5})` returns the string `{"x":5}`.

The method is part of JavaScript’s built-in JSON object and is paired with `JSON.parse()`. Stringify moves from a JavaScript value to JSON text; parse performs the reverse operation by turning JSON text into a JavaScript value. The names are easy to mix up, especially because both methods belong to the same object.

Serialization has important edge cases. In objects, `undefined`, functions, and symbol-valued properties are omitted; inside arrays, those values become `null`. Dates are converted through their `toJSON()` behavior, normally producing an ISO-style timestamp. Circular references cause a `TypeError`, and BigInt values cannot normally be serialized.

The optional second argument, called a replacer, can transform values or select properties. A third `space` argument adds indentation for human-readable output, although whitespace changes the presentation rather than the underlying data.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: