What you can do here
- JSON stringify:
JSON.stringify(value), the compact one-line form - JSON serialize with indentation:
JSON.stringify(value, null, 2) - JSON to string: wrap the JSON in quotes and escape it, ready for JavaScript, an API field, a log or a test fixture
- Parse / unstringify: turn
"{\"a\":1}"back into{"a":1}, even when it was stringified twice - Sort keys alphabetically for stable output and cleaner diffs
Links for each operation: ?mode=compact, ?mode=pretty, ?mode=string and ?mode=parse.
Stringify, serialize and “to string” compared
| Operation | Equivalent code | Output for {"a": "x y"} |
|---|---|---|
| Stringify (compact) | JSON.stringify(v) | {"a":"x y"} |
| Serialize (indented) | JSON.stringify(v, null, 2) | { / "a": "x y" / } |
| JSON to string | JSON.stringify(JSON.stringify(v)) | "{\"a\":\"x y\"}" |
| Parse string to JSON | JSON.parse(JSON.parse(s)) | {"a":"x y"} |
Stringifying parses the input first, so invalid JSON — a trailing comma, single-quoted keys, a missing comma — is rejected with the parser's error rather than passed through. Only whitespace between tokens changes; key order, array order, numbers and string contents are kept exactly (unless you tick Sort keys).
Worked example
Input:
{
"name": "Ada",
"roles": ["admin", "user"],
"active": true
}
Stringify: {"name":"Ada","roles":["admin","user"],"active":true}
JSON to string: "{\"name\":\"Ada\",\"roles\":[\"admin\",\"user\"],\"active\":true}"
When you need each one
- Compact: an environment variable, a one-record-per-line NDJSON log, a shell one-liner, a spreadsheet cell or database column.
- Indented: reading an API response, a fixture in version control, a config file.
- JSON to string: a JSON document stored inside another JSON field (webhooks, message queues, DynamoDB), a string constant in JavaScript, Java or C#, or a
-dargument that must be quoted. - Parse: a log or API that returned
"{\"id\":1}"(double-encoded JSON) and you want the real object.
Common questions
Is this the same as JSON.stringify in JavaScript?
Yes. The input is read with JSON.parse and written with JSON.stringify, with no spacer for compact output or 2, 4 or a tab for indented output.
How is JSON stringify different from JSON minify?
For valid JSON the compact output is identical: both produce the shortest legal form of the same data. The JSON minifier adds size and gzip statistics.
How do I convert JSON to a string?
Choose JSON to string. The JSON is compacted, every " and backslash is escaped, and the result is wrapped in quotes: "{\"a\":1}". Pick single quotes for JavaScript or SQL code that uses them.
How do I turn a stringified JSON string back into JSON?
Choose Parse string to JSON and paste the quoted value. It is unwrapped until it is real JSON (double-stringified values are handled too) and shown indented.
Does it reorder keys or change values?
No, unless you tick Sort keys. Very large integers beyond 253 lose precision, exactly as they do in JSON.parse.
Is my JSON uploaded?
No. Parsing and stringifying run in your browser; nothing leaves the page.