JSON Formatter
Paste JSON to pretty-print it with your choice of indentation, or minify it back down. Invalid JSON gets a message that names the line and column, not a raw exception.
How it works
The formatter parses your text with the browser's own JSON parser, then re-serialises it with the indentation you choose. Because it is a real parse rather than a text transformation, anything that comes out the other side is guaranteed to be valid JSON.
When the parse fails, the raw error only gives a character offset. The tool converts that offset into a line and column so you can go straight to the problem — usually a trailing comma, a single quote, or an unquoted key.
The formula
Format
JSON.stringify(JSON.parse(input), null, indent)
Minify
JSON.stringify(JSON.parse(input))
Sort keys
recursively rebuild every object with its keys in A→Z order
Worked examples
| Scenario | Working | Result |
|---|---|---|
| Minified API response | Format with 2 spaces: {"id":1,"tags":["a","b"]} | Readable, nested, one key per line |
| Trailing comma | {"a": 1,} | Error names line 1, column 9 |
| Config file for a diff | Format with sorted keys | Stable key order, so diffs show only real changes |
When you'd use it
- Reading a minified API response
- Finding the syntax error in a config file that will not load
- Normalising key order before comparing two files
- Shrinking JSON before pasting it into a request body
Common questions
Is my JSON uploaded to a server?
No. Parsing and formatting happen in your browser with the built-in JSON parser. Nothing you paste leaves your machine, which matters when the payload contains tokens or customer data.
Why does my JSON say “unexpected token” when it looks fine?
The three usual causes are a trailing comma before a closing brace or bracket, single quotes instead of double quotes, and unquoted object keys. JSON is stricter than JavaScript object syntax about all three.
Can it handle JSON with comments or JSONC?
No. Comments are not part of the JSON specification, so the parser rejects them. Strip comments first if you are working with a tsconfig-style file.
What does sorting keys do to arrays?
Nothing. Array order is meaningful in JSON, so it is preserved exactly. Only object keys are reordered.

