All tools

JSON.stringify() Online

Convert JavaScript objects to JSON strings instantly

100% in-browserNo signupFree forever
Object → JSON string
Spaces: 2

Quick Examples

What is JSON.stringify()?

JSON.stringify() is a built-in JavaScript method that converts JavaScript objects, arrays, or values into JSON (JavaScript Object Notation) strings. This is essential for:

  • Sending data to web servers via HTTP requests
  • Storing data in localStorage or sessionStorage
  • Converting objects to strings for transmission
  • Creating JSON files from JavaScript data

Use our free JSON Beautifier to format the stringified output, or our JSON Fixer to repair any issues.

Syntax

JSON.stringify(value, replacer, space)

value

The JavaScript object, array, or value to convert to JSON string

replacer (optional)

A function or array to transform values before stringifying

space (optional)

Number of spaces for indentation (0-10) for pretty printing

Examples

Simple Object:

const obj = { name: "John", age: 30 };
JSON.stringify(obj);
// Output: '{"name":"John","age":30}'

With Pretty Print (spaces = 2):

JSON.stringify(obj, null, 2);
// Output:
// {
//   "name": "John",
//   "age": 30
// }

More JSON Tools

Need to parse JSON strings? Use our JSON Beautifier or JSON Fixer for validation and repair.

What Is JSON.stringify()?

JSON.stringify() is a built-in JavaScript function that converts a value — an object, array, number, string, or boolean — into a JSON-formatted string. It is the standard way to serialize data for sending over a network, storing in localStorage, writing to a file, or logging structured output.

The function accepts three parameters: the value to serialize, an optional replacer (a function or array that filters which keys are included), and an optional space parameter that controls indentation. Passing 2 as the space argument produces readable, pretty-printed JSON — for example, JSON.stringify({name:"Alice"}, null, 2) outputs a formatted JSON object with each key on its own indented line. Passing null or omitting space produces compact, minified JSON with no whitespace.

This tool simulates JSON.stringify() directly in your browser. Paste any JavaScript object literal, choose your indentation and options, and instantly see the serialized JSON string output — no Node.js runtime required.

How it works

Stringify a JavaScript Object in Seconds

01

Paste your JS object

Paste a JavaScript object literal, JSON, or any serializable value into the input panel.

02

Choose indent and options

Select indentation (2 spaces, 4 spaces, tab, or none for minified output) and toggle options like removing undefined values.

03

Get the JSON string

The output panel shows the result of JSON.stringify() with your chosen settings, updated in real time.

04

Copy the output

Copy the serialized JSON string for use in API requests, localStorage, config files, or debug logs.

Use cases

When Developers Use JSON.stringify()

📡

API Request Bodies

Serialize a JavaScript object to JSON before sending it as the body of a fetch or axios POST request.

💾

localStorage Storage

localStorage only stores strings. Use JSON.stringify() to serialize objects before saving and JSON.parse() to restore them.

📋

Log Serialization

Pretty-print complex objects in server logs or browser console with indentation so nested data is readable.

⚙️

Config Serialization

Convert in-memory configuration objects to a JSON string for writing to config files or sending to a settings API.

🐛

Debug Output

Inspect the exact serialized form of an object to understand what JSON.stringify() includes, excludes, and transforms.

🔁

Deep Clone via parse+stringify

The JSON.parse(JSON.stringify(obj)) pattern creates a deep clone of an object — useful for simple data structures without circular refs.

FAQ

Frequently Asked Questions

1What is JSON.stringify() in JavaScript?
JSON.stringify() is a built-in JavaScript function that converts a value — object, array, number, string, or boolean — into a JSON-formatted string. It is the standard way to serialize data for network requests, localStorage, or file output.
2How do I pretty-print JSON with JSON.stringify()?
Pass a number as the third argument: JSON.stringify(obj, null, 2) indents with 2 spaces. Use "\t" instead of a number for tab indentation. Omit the argument or pass null for minified, compact output.
3How do I handle circular references in JSON.stringify()?
A TypeError: Converting circular structure to JSON occurs when an object contains a reference back to itself. Fix it with a custom replacer function that tracks seen objects, or use a library like flatted or json-stringify-safe.
4Why does JSON.stringify() return undefined for some values?
It returns undefined (not the string) when passed a function, Symbol, or undefined at the top level. Object properties with these types are silently omitted. Array elements with undefined are replaced with null to preserve index positions.
5How do I stringify a JavaScript Date object?
JSON.stringify() calls .toISOString() on Date objects, producing a string like "2024-01-15T12:00:00.000Z". When parsing back with JSON.parse(), the value is returned as a string — not a Date — so you need a reviver function to convert it back.
6How do I use the replacer parameter in JSON.stringify()?
Pass an array of key names to include only those keys: JSON.stringify(obj, ["name", "age"]). Pass a function to transform values during serialization: JSON.stringify(obj, (key, val) => val === undefined ? null : val).
7What is the difference between JSON.stringify() and JSON.parse()?
JSON.stringify() serializes a JavaScript value into a JSON string. JSON.parse() does the reverse — it deserializes a JSON string back into a JavaScript value. Together they form the basis of JSON serialization in JavaScript.
8How do I stringify JSON in Python?
Use json.dumps() from the built-in json module. For pretty-printing: json.dumps(obj, indent=2). To sort keys: json.dumps(obj, sort_keys=True). For non-serializable types: json.dumps(obj, default=str).
9How do I minify JSON with JSON.stringify()?
Call JSON.stringify(obj) with no space argument, or pass null or 0: JSON.stringify(obj, null, 0). This produces compact JSON with no whitespace — ideal for reducing network payload size.
10What is the difference between JSON.stringify() and a JSON formatter?
JSON.stringify() serializes a JavaScript value into a JSON string (serialization). A JSON formatter takes an existing JSON string and re-formats it with indentation for readability. This tool does the former; use the JSON Beautifier for the latter.
11How do I stringify JSON without escaping Unicode?
By default JSON.stringify() includes non-ASCII characters like emojis as-is without escaping. Only characters that must be escaped in JSON (control characters, quotes, backslashes) are escaped. If you need full Unicode escaping, use a custom replacer or a dedicated library.
12How do I stringify a BigInt in JSON?
JSON.stringify() throws a TypeError for BigInt by default. Workarounds: (1) use a replacer that converts BigInt to string; (2) add a BigInt.prototype.toJSON method; or (3) convert BigInt values to strings or numbers before serializing.
Learn more

Developer Guides

Feedback for json_stringify_online

Tell us what's working, what's broken, or what you wish we built next — it directly shapes our roadmap.

You make the difference

Good feedback is gold — a rough edge you hit today could be smoother for everyone tomorrow.

  • Feature ideas often jump the queue when lots of you ask.
  • Bug reports with steps get fixed faster — paste URLs or examples if you can.
  • Name and email are optional; we won't use them for anything except replying if needed.

Stay Updated

Get the latest tool updates, new features, and developer tips delivered to your inbox.

What you'll get
  • Product updates & new tools
  • JSON, API & developer tips
  • Unsubscribe anytime — no hassle

Get in touch

Feature ideas, bugs, or a quick thanks — we read every message.