Favorites

JavaScript JSON.stringify() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
JSON.stringify()
JavaScript JSON Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

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 BigInt values.

Example

const order = { id: 7, items: ['tea'], placed: new Date(0), note: undefined };
console.log(JSON.stringify(order));
console.log(JSON.stringify(order, null, 2));
console.log(JSON.stringify(order, ['id', 'items']));
console.log(JSON.stringify([NaN, () => 1]));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee