JSON.stringify() is a JavaScript method that converts a JavaScript value—such as an object, array, or primitive—into a JSON-formatted string. It is commonly used for serializing data for storage, transmission, or debugging.

Key Features

  • Basic Usage:

    JSON.stringify({ name: "Alice", age: 30 });
    // Returns: '{"name":"Alice","age":30}'
  • Supports Arrays and Nested Objects:

    JSON.stringify([1, "hello", { nested: true }]);
    // Returns: '[1,"hello",{"nested":true}]'
  • Handles Special Values:

    • undefined, function, and Symbol values are omitted from objects or converted to null in arrays.

    • null, Infinity, and NaN are converted to null.

    • Date objects are converted to ISO strings (e.g., "2026-02-04T00:00:00.000Z").

    • BigInt values throw a TypeError unless a toJSON() method is defined.

  • Replacer Parameter:
    Allows filtering or transforming values during stringification:

    JSON.stringify({ a: 1, b: 2 }, (key, value) => {
      return key === 'a' ? undefined : value;
    });
    // Returns: '{"b":2}'
  • Space Parameter (Pretty-Print):
    Adds indentation for readability:

    JSON.stringify({ a: 1, b: 2 }, null, 2);
    // Returns:
    // {
    //   "a": 1,
    //   "b": 2
    // }

Limitations

  • Circular References: Throws a TypeError if the object contains self-references.

  • Unsupported Types: Map, Set, WeakMap, WeakSet, and Error objects are converted to {}.

  • No Built-in Support for Custom Types: Requires manual handling via toJSON() or external libraries.

Common Use Cases

  • Sending data to APIs.

  • Storing data in localStorage.

  • Debugging complex objects.

  • Converting JavaScript data to a transportable format.

Note: For deep cloning with circular references, consider using structuredClone() instead of JSON.stringify() and JSON.parse().

There is a way to serialize a function in JS, but you'll have to eval it on the other side and it will also lose access to it's original scope. A way to do it would be:

CopyJSON.stringify(objWithFunction, function(key, val) {
  if (typeof val === 'function') {
    return val + ''; // implicitly `toString` it
  }
  return val;
});

There are some legitimate uses for what you're asking despite what people are posting here, however, it all depends on what you're going to be using this for. There may be a better way of going about whatever it is you're trying to do.

Answer from chjj on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript | MDN
The JSON.stringify() static method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
🌐
W3Schools
w3schools.com › js › js_json_stringify.asp
JSON.stringify()
JSON.stringify() can not only convert objects and arrays into JSON strings, it can convert any JavaScript value into a string.
Discussions

JSON.stringify function
Take a look at JSONfn plugin. ... doesnt stringify getter setter, also when it returns type of object said to be some kind of Object, not the Type i had defined before... More on stackoverflow.com
🌐 stackoverflow.com
JSON stringify a Set
For anyone else coming here later ... this, JSON.parse takes an equivalent function called reviver that's run on everything it parses. I ended up solving this by adding "__isSet" to the start of any array made out of a set and then checking for this in the reviver function, turning it back into a set when found. 2023-04-26T00:29:40.077Z+00:00 ... While all of the above work I suggest that you subclass set and add a toJSON method to make sure that it stringify's ... More on stackoverflow.com
🌐 stackoverflow.com
JSON stringify objects with json strings already as values
Might be a duplicate question, but couldn't find the answer. I want to stringify a javascript object that contains some JSON strings as values. More on stackoverflow.com
🌐 stackoverflow.com
[AskJS] PETITION: Make JSON.stringify use any object's toString method internally!
.toJSON already exists, it's just a not well known feature of JS. 6th bullet point. More on reddit.com
🌐 r/javascript
16
0
January 3, 2024
🌐
JSON Formatter
jsonformatter.org › json-stringify-online
JSON Stringify Online using JSON.Stringify()
JSON Stringify Online is very unique tool for convert JOSN to String and allows to download, save, share and print JSON to TSV data..
🌐
JSONLint
jsonlint.com › json-stringify
JSON Stringify - Escape JSON for Embedding | JSONLint | JSONLint
JSON Stringify converts a JSON object into an escaped string. The result can be safely embedded inside another string—in code, databases, or even nested within other JSON.
🌐
npm
npmjs.com › package › fast-json-stringify
fast-json-stringify - npm
3 weeks ago - Stringify your JSON at max speed. Latest version: 6.2.0, last published: 6 hours ago. Start using fast-json-stringify in your project by running `npm i fast-json-stringify`. There are 194 other projects in the npm registry using fast-json-stringify.
      » npm install fast-json-stringify
    
Published   Jan 15, 2026
Version   6.2.0
Author   Matteo Collina
🌐
Online Tools
onlinetools.com › json › stringify-json
Stringify JSON – Online JSON Tools
We call the JSON.stringify() function on the input data and it converts line breaks into "\n" escape sequences, quotes into "\"" escape sequences, and tabs into "\t" escape sequences.
Find elsewhere
🌐
V8
v8.dev › blog › json-stringify
How we made JSON.stringify more than twice as fast · V8
At the end, the final result is constructed by simply concatenating the output from the initial one-byte stringifier with the output from the two-byte one. This strategy ensures we stay on a highly-optimized path for the common case, while the transition to handling two-byte characters is lightweight and efficient. Any string in JavaScript can contain characters that require escaping when serializing to JSON (e.g.
🌐
Zhenghao
zhenghao.io › posts › json-oddities
JSON and the stringification oddities in JavaScript
In JavaScript, the way to convert a value to a JSON string is via JSON.stringify.
🌐
Reddit
reddit.com › r/javascript › [askjs] petition: make json.stringify use any object's tostring method internally!
Make JSON.stringify use any object's toString method ...
January 3, 2024 -

What do you guys think? Should I make an official proposal? What would be the best way to make such spec proposal?

And tell me what you think! The idea is for any object's toString method override the way JSON.stringify creates the string. For example:

var vec =
{
    x: 0,
    y: 0,
    toString() => `[${this.x},${this.y}]`
}

JSON.stringify(vec) //will return: '[0,0]'

This way I won't need to use a custom stream to alter a big object when converting it to JSON!

Or would you say this is very unnecessary, even if an easy thing to add to JS?

🌐
Medium
medium.com › @akhil-mottammal › demystifying-json-stringify-and-json-parse-2699e4f0048e
Demystifying JSON.stringify() and JSON.parse() | by Akhil Mottammal | Medium
February 22, 2024 - JSON.stringify() is a method in JavaScript that converts a JavaScript object or value into a JSON string. This is useful for serializing…
🌐
Online String Tools
onlinestringtools.com › json-stringify-string
JSON Stringify a String – Online String Tools
This tool converts a string to a JSON string. This is done by calling JSON.stringify() function on the input string. This function adds double quotes at the beginning and end of the input string and escapes special JSON characters.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-json-stringify-method
JavaScript JSON stringify() Method - GeeksforGeeks
July 11, 2025 - The JSON.stringify() method in JavaScript is used to convert JavaScript objects into a JSON string.
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-json-parse-stringify
How To Use JSON.parse() and JSON.stringify() | DigitalOcean
November 24, 2021 - JSON.stringify() takes a JavaScript object and transforms it into a JSON string.
🌐
YouTube
youtube.com › watch
Let's Unpack JSON Stringify - YouTube
Let's have a look at the hidden gems found in JSON.Stringify - there's more than you think. And it's not just indentation.For your reference, check this out:...
Published   September 17, 2024
🌐
Reddit
reddit.com › r/programming › how we made json.stringify more than twice as fast
r/programming on Reddit: How we made JSON.stringify more than twice as fast
August 4, 2025 - I would challenge you to work your ass off to find at least another 20%. JSON.stringify fucks up everything else about Node concurrency.
🌐
ServiceNow Community
servicenow.com › community › developer-articles › json-stringify-making-json-look-pretty-and-perfect › ta-p › 2534944
JSON.stringify() - Making JSON Look Pretty and Per... - ServiceNow Community
April 17, 2023 - Well, let's say you're working on a project and you need to update a worknote or comment on a string field. It can get pretty confusing when you're trying to read through all that jumbled up text. But with JSON.stringify(), you can make that messy JSON look clean and organized, making it much easier to understand.