Developer Guide
Convert JSON to String
Stringify JSON in the browser: pretty-print with 2-space indent, minify, or escape one string field. Covers dates, circular references, and JSON.stringify.
JSON.stringify turns a value into a string. Pretty-print is the same function with a 2-space indent. Minify is the same function with no extra whitespace. Escaping a single field — quotes, newlines, backslashes — is not stringify of a document; it is JSON.stringify on one string, optionally with the surrounding quotes stripped.
/tools/json-formatter pretty-prints, minifies, and validates whole documents (2-space indent on Format). /tools/json-escape targets one string value. Mixing those two is how people “stringify” a paragraph and then cannot parse the file. This page separates the jobs.
Pretty 2-space versus minify versus JSON.stringify
In JavaScript, JSON.stringify(value, null, 2) is what Format does after JSON.parse. Minify is JSON.stringify(value) with no spacer. Validate parses and, on success, says Valid JSON without rewriting.
Pretty output is for humans, diffs, and fixtures. Minified output is for the wire. Both are strings. Neither changes types: numbers stay numbers, true stays boolean, keys stay double-quoted. Trailing commas, single quotes, and comments are not JSON — the formatter reports line and column instead of guessing.
Escaping a string field is a different tool
If the job is “put this sentence inside a JSON value,” do not run the whole-document formatter on the sentence. A newline in the sentence must become \n; a quote must become \". /tools/json-escape uses JSON.stringify(input) on that string. Wrap-quotes on keeps the surrounding "; wrap-quotes off is the inner payload you paste between existing quotes.
Example: He said "hi" escapes to He said \"hi\" (unwrapped) or "He said \"hi\"" (wrapped). A document formatter would instead demand {...} and fail. Unescape reverses the field, not the document.
What stringify does to Date, undefined, and NaN
JSON.stringify calls toJSON on Date, so you get an ISO-8601 string: new Date("2023-11-14T22:13:20.000Z") becomes "2023-11-14T22:13:20.000Z". That is text, not a date type — JSON has no date type. On the way back you parse the string yourself.
undefined, functions, and symbols on objects are omitted. NaN and Infinity become null. Arrays keep holes as null. If you needed those values preserved, JSON is the wrong format; encode them explicitly as strings or drop them before you stringify.
Circular references
JSON.stringify throws TypeError: Converting circular structure to JSON when an object points at itself (const o = {}; o.self = o). DOM nodes, some ORM models, and request objects do this. The formatter will not walk a cycle either — it only parses text you paste, so the throw happens in your app before the text exists.
Fix it in code: a replacer that records seen objects, or a plain DTO with the fields you actually need. Then paste the result into /tools/json-formatter to confirm it parses. Pretty-print will not remove a cycle that is still in the object graph.
localStorage, APIs, and logs
localStorage stores strings. JSON.stringify then JSON.parse is the usual round trip. APIs send the minified form. Logs sometimes pretty-print; sometimes they concatenate two objects without a newline, which is invalid JSON — the formatter’s line/column error is the right debug tool, not another stringify.
Sort keys on the formatter if you need stable golden files. Sorting is for humans and tests; JSON object key order is not a spec-level equality.
Common pitfalls
Running json-escape on a whole document turns every quote into \" and produces a string, not an object you can parse as the original tree. Running the formatter on a raw paragraph fails because the paragraph is not JSON.
Stringifying a Date and later treating the result as epoch seconds will not match 1700000000. Stringifying a Map or Set yields {}. Stringifying undefined at the root yields undefined (the JS value), not the text null — JSON.parse cannot read that.
- Format on
/tools/json-formatter=JSON.stringify(value, null, 2). - Minify =
JSON.stringify(value)with no indent. /tools/json-escapeis for one string value, not a document.
Worked examples
Pretty-print (2-space)
{"name":"Ada","ok":true}{
"name": "Ada",
"ok": true
}Format on /tools/json-formatter. Minify returns the compact input shape (whitespace aside).
Escape a string field, not a document
He said "hi"
next lineHe said \"hi\"\nnext lineThat is /tools/json-escape with wrap-quotes off. Wrap-quotes on adds a leading and trailing ".
Date becomes an ISO string
JSON.stringify({ at: new Date("2023-11-14T22:13:20.000Z") })
// {"at":"2023-11-14T22:13:20.000Z"}JSON has no Date type. 1700000000 is a number you would put in the field yourself if you want Unix seconds.
Frequently asked questions
Should I pretty-print JSON on the wire?
Usually no. Minify for APIs. Pretty-print for files humans edit and for debugging in /tools/json-formatter.
Why does stringify throw on my object?
A circular reference, or a toJSON that throws. Flatten the object, then validate the text in the formatter.
How do I embed a paragraph inside JSON?
Escape the paragraph on /tools/json-escape and paste it as a value. Do not format the paragraph as if it were a document.
What indent does the formatter use?
Two spaces (JSON.stringify(value, null, 2)). It does not offer tabs or four-space indent.
Is my JSON uploaded?
No. Parse, stringify, and escape all run in the browser. There is no stringify endpoint on thedevtools.in.
Summary
Stringify a document with Format (2-space) or Minify on /tools/json-formatter. Escape one messy string on /tools/json-escape. Expect Date to become ISO text, expect cycles to throw, and do not confuse those two tools. Validate the result with JSON.parse — which is what the formatter already did.