Home → JSON Stringify Online

JSON Stringify Online

JSON.stringify converts a JavaScript object into a JSON string.

About This Tool

JSON.stringify converts a JavaScript object into a JSON string. This tool runs entirely in your browser — no data is ever sent to a server. Free to use, no account required.

What JSON Stringify Does

JSON.stringify() is the built-in JavaScript method for converting values to JSON strings. Understanding its behavior helps avoid common serialization pitfalls.

Basic Stringification

Objects and arrays are converted to their JSON representation: keys become quoted strings, values maintain their type, and the structure is preserved. Numbers, strings, and booleans serialize directly to their JSON equivalents.

Handling Special Values

Undefined values, functions, and symbols are not valid JSON. In objects these properties are silently omitted. In arrays they become null. NaN and Infinity also become null in JSON output.

Stringify Options: Replacer and Space

JSON.stringify accepts two optional parameters that give you fine-grained control over serialization output.

Using the Space Parameter

The space parameter controls indentation. Pass 2 or 4 for space-indented output, or "\t" for tabs. Without a space parameter, output is compact with no whitespace — ideal for network transmission.

Using a Replacer

A replacer function or array filters or transforms values during serialization. An array of key names acts as an allowlist. A function receives each key and value and can return a transformed value or undefined to omit the property.

Frequently Asked Questions

What is JSON stringify?+
JSON stringify converts a JavaScript value — such as an object, array, number, or boolean — into a JSON-formatted string. This is the standard way to serialize data for storage in localStorage, sending in HTTP requests, or saving to a file.
What happens to undefined, functions, and symbols in JSON.stringify?+
JSON does not support undefined, functions, or symbols. When stringifying an object, properties with these values are omitted entirely. In arrays, they are replaced with null to preserve the array length.
How do I pretty-print with JSON stringify?+
Pass a number as the third argument (the space parameter) to JSON.stringify. For example, JSON.stringify(obj, null, 2) produces output with 2-space indentation. Pass '\t' to use tabs. This is equivalent to pretty printing.
Can JSON stringify handle circular references?+
Standard JSON.stringify throws a TypeError if the object contains circular references. To handle them, use a custom replacer function or a library like flatted. This tool detects circular references and shows a clear error message.

JSON.stringify() Complete Reference

JSON.stringify() converts a JavaScript value to a JSON string. Understanding all its options and edge cases prevents common serialization bugs.

JSON.stringify() Syntax and Options

// Basic usage
JSON.stringify(value)
JSON.stringify(value, replacer)
JSON.stringify(value, replacer, space)

// Examples
JSON.stringify({a:1,b:2})         // '{"a":1,"b":2}'
JSON.stringify({a:1}, null, 2)    // pretty with 2-space indent
JSON.stringify({a:1}, ["a"])      // only include key "a": '{"a":1}'
JSON.stringify({a:1}, (k,v) => v === 1 ? undefined : v) // filter

// Replacer function
const replacer = (key, value) => {
  if (key === "password") return undefined; // omit password
  if (key === "date" && value instanceof Date) return value.toISOString();
  return value;
};
JSON.stringify(user, replacer, 2);

JSON.stringify() Edge Cases

Value Typestringify() Behavior
undefinedOmitted in objects, null in arrays
functionOmitted in objects, null in arrays
SymbolOmitted in objects, null in arrays
NaN / InfinityConverted to null
Date objectConverted to ISO string via .toJSON()
BigIntThrows TypeError — needs custom replacer
Circular referenceThrows TypeError — needs serializer
toJSON() methodCustom serialization if defined on object

Handling Circular References

// Circular reference workaround
function safeStringify(obj) {
  const seen = new WeakSet();
  return JSON.stringify(obj, (key, value) => {
    if (typeof value === "object" && value !== null) {
      if (seen.has(value)) return "[Circular]";
      seen.add(value);
    }
    return value;
  }, 2);
}

Explore more tools: All JSON Tools | Validator | Pretty Print | JSON Diff