What is JSON stringify?
Stringify wraps a JSON value into an escaped string literal, a JSON string that contains your serialized JSON. It's the serialize-and-escape step so a value can be safely embedded where a string is required: inside another JSON payload, a database text column, a log line, or a source-code constant.
It mirrors JavaScript's JSON.stringify(value, replacer, space) followed by quoting the result. Parse / unescape is the inverse. Everything runs 100% in-browser with zero network requests.
Edge cases & gotchas
- Output is a single-quoted literal wrapping compact JSON. Since JSON itself uses double quotes, the literal stays readable with no
\"noise, and pastes cleanly into JS or Python source. - Apostrophes and backslashes inside string values are escaped (
\',\\) so the literal reproduces the exact JSON text. - Single-quoted literals aren't valid JSON; they're for embedding in code. Need a JSON-legal escaped body instead? Use Escape.
- Repair-aware parsing tolerates single quotes, trailing commas, and Python literals before serializing.
NaN,Infinity,-Infinityserialize tonull(JS semantics);BigIntthrows.- Dates aren't a JSON type. They serialize as ISO-8601 strings via
toJSON()and don't round-trip back to Date automatically.
JSON.stringify argument & type reference
| Arg | Type | Purpose |
|---|---|---|
| value | any | Value to serialize |
| replacer | function | array | Transform each entry, or whitelist property names |
| space | number | string | Indentation (≤10 spaces, or a string like "\t") |
| Input | Result |
|---|---|
| undefined / function / Symbol (in object) | omitted |
| undefined / function / Symbol (in array) | null |
| NaN / Infinity | null |
| BigInt | TypeError |
| Date | ISO string via toJSON() |
| Map / Set | {} |
| circular reference | TypeError |
How to use
- Paste or upload JSON. Repair-aware parsing tolerates minor syntax issues.
- The tool serializes and escapes the value into a string literal.
- Copy the output (wrapping quotes included) for embedding in source, JSON, or a database field.
- To reverse, use Unescape / parse to recover the original value.
- Verify zero network requests in DevTools → Network; everything runs client-side.
Examples
Basic object → string literal
{"name":"John","age":30}'{"name":"John","age":30}'Single-quoted input is repaired first (edge case)
{'id': 42, 'tags': ['json', 'diff'], 'active': true}'{"id":42,"tags":["json","diff"],"active":true}'Apostrophes & escapes inside values
{"msg":"it's a line\nbreak"}'{"msg":"it\'s a line\\nbreak"}'FAQ
What is the difference between stringify and escape?
Escape outputs only the escaped body (no wrapping quotes); stringify produces a full JSON string literal with surrounding quotes.
What does the JSON.stringify replacer argument do?
It's an optional 2nd arg: a function to transform each key/value, or an array of property names to whitelist. JSON.stringify(obj, ["week","month"]) keeps only those keys.
What is the space argument?
The optional 3rd arg controls indentation: a number (spaces, max 10) or a string like "\t". Purely for pretty-printing.
Why did my undefined / function / Symbol values disappear?
In JavaScript's JSON.stringify they aren't valid JSON: omitted inside objects, converted to null inside arrays. Symbol keys are always ignored.
Why do I get a "circular reference" error?
JSON.stringify throws a TypeError on objects that reference themselves. Remove the cycle, or use a replacer / structuredClone before serializing.
Why do I see double backslashes where I expected single?
You stringified twice (double-escaping). Unescape / parse once to undo it.