Quick Tip: Paste any JSON value, choose your indent level, then copy the stringified result directly into your code.
Indent:
52B → 39B
JSON Input
Stringified Output

JSON Stringify: Serialise JSON for Code

JSON.stringify() converts a JavaScript value into a JSON string. This tool lets you paste any JSON, choose your indent level, and instantly see the stringified output — ready to embed in your source code or send over the wire.

  • Compact output: Zero indent removes all whitespace — ideal for API payloads.
  • Indented output: Choose 2, 4 spaces or tabs for readable code.
  • String literal mode: Wraps the result in quotes with internal quotes escaped — paste straight into code.
  • Privacy-First: All processing is done locally in your browser.

JSON.stringify() Quick Reference

The full signature is JSON.stringify(value, replacer, space). The space argument controls indentation (0 = compact, 2 or 4 = readable). A replacer function or array can filter which keys are included.

CallOutput style
JSON.stringify(obj)Compact — one line, no spaces
JSON.stringify(obj, null, 2)Indented with 2 spaces
JSON.stringify(obj, null, 4)Indented with 4 spaces
JSON.stringify(obj, null, "\t")Indented with tabs
JSON.stringify(obj, ["id", "name"])Only id and name keys included

Stringify in Practice

Input JSON

{
  "id": 1,
  "name": "Alice",
  "active": true
}

Compact (indent 0)

{"id":1,"name":"Alice","active":true}

As JS string literal

"{\"id\":1,\"name\":\"Alice\",\"active\":true}"

Common Use Cases

Embed in Source Code

Copy a compact JSON string literal to hardcode data in JavaScript, TypeScript, or Python source files.

API Payload Prep

Convert a pretty-printed JSON object to a minimal single-line string ready to paste into curl or Postman.

localStorage / Cookies

Serialise objects before storing them in localStorage.setItem() or encoding into URL parameters.


Frequently Asked Questions

Is my data safe with this JSON tool?

Yes. This tool uses 100% client-side processing. Your JSON data never leaves your browser and is never sent to our servers, ensuring maximum privacy and security.

What is the difference between compact and string literal output?

Compact output is the raw JSON string — useful for API calls or storage. String literal mode wraps the result in double quotes and escapes internal quotes (\"), so you can paste it directly as a string value in JavaScript or Python source code.

Does JSON.stringify preserve number precision?

JSON.stringify uses standard JavaScript number serialisation. Very large integers (> 2^53) may lose precision because JavaScript represents all numbers as 64-bit floats. Use a BigInt-aware serialiser for such values.

What values does JSON.stringify skip?

JSON.stringify omits object properties whose value is undefined, a function, or a Symbol. In arrays, such values are serialised as null. Use a replacer function if you need to handle them differently.