JavaScript JSON.stringify() Method
The JSON.stringify() static method converts a JavaScript value, such as an object or array, into a JSON string. It can also pretty-print with indentation.
Description
The JSON.stringify() static method converts a value to a JSON string, ready to send to a server or store in localStorage. The third argument adds indentation for readable output, and the replacer argument lets you filter or transform values.
Not everything survives: functions, undefined and symbols are left out of objects (or become null in arrays), NaN and Infinity become null, Date objects become ISO strings, and Map and Set become empty objects. Objects can control their output with a toJSON() method. Circular references and BigInt values throw a TypeError.
When the replacer is a function, it's called for every key and value, including the root with an empty key, and whatever it returns is used instead; returning undefined leaves the property out. This is how you can handle values like BigInts, Map objects or sensitive fields such as passwords. The order of properties in the output follows the object's own property order.
Syntax
JSON.stringify(value)
JSON.stringify(value, replacer)
JSON.stringify(value, replacer, space)Parameters
- valueThe value to convert to JSON.
- replacerOptional. A function that changes values as they are converted, or an array of property names to include.
- spaceOptional. A number of spaces, or a string, to indent the output with for readability.
Return Value
A JSON string, or undefined for values such as functions and undefined itself.
Exceptions
- TypeErrorThrown for circular references or
BigIntvalues.
Example
Browser Support
The following information will show you the current browser support for the JSON.stringify() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





