JSON formatter & validator
Pretty-print, minify and validate JSON. Paste JSON, get readable output or a clear error — all in your browser.
What this JSON formatter does
Paste any JSON document and either pretty-print it with consistent
indentation or minify it to a single line. The tool is a thin UI over the
browser’s native JSON.parse and JSON.stringify, which means two things:
it is as strict as the JSON spec (RFC 8259), and it is instant even for
multi-megabyte API responses. If the input does not parse, you see the exact
error the engine produced instead of a vague “invalid JSON” message. Nothing
leaves your browser.
How to use it
- Paste your JSON into the JSON box (the sample shows the expected shape).
- Pick an Indent width — 2 spaces (the default used by most formatters and Prettier) or 4 spaces.
- Click Format for readable output or Minify for the compact form.
- If parsing fails, a red error line replaces the result. Fix the input and click again — the tool does not re-run on every keystroke, so you can edit freely.
- Use Copy on the result to grab the output.
Reading the error message
Because the parser is the browser’s own, the wording differs slightly between engines, but all of them tell you where it stopped:
| Browser | Typical message |
|---|---|
| Chrome / Edge (V8) | Unexpected token } in JSON at position 42 |
| Firefox | JSON.parse: unexpected character at line 3 column 7 of the JSON data |
| Safari | JSON Parse error: Unexpected identifier "foo" |
“Position 42” counts characters from the start of the input, including newlines. The most common failures, roughly in order of frequency:
| Input | Why it fails | Fix |
|---|---|---|
{"a": 1,} | Trailing comma | Remove the last comma |
{'a': 1} | Single quotes | Use double quotes for keys and strings |
{a: 1} | Unquoted key | Quote the key: {"a": 1} |
// comment | Comments are not JSON | Strip them (JSONC is not JSON) |
{"x": NaN} | NaN, Infinity, undefined are not JSON values | Use null or a string |
{"p": "C:\Users"} | Backslash must be escaped | Write "C:\\Users" |
[1, 2, 3 | Unbalanced brackets | Close the array |
A sneaky one: pasting from a chat app or a PDF often brings in “smart” quotes
(“ ”) or a non-breaking space, both of which look fine but are not valid
tokens. Re-type the quote and the error disappears.
Things JSON.stringify changes silently
Formatting is lossless for ordinary data, but a few JavaScript rules apply because the tool round-trips through a real object:
- Big integers lose precision.
{"id": 12345678901234567890}becomes12345678901234567000. Anything aboveNumber.MAX_SAFE_INTEGER(9007199254740991) is at risk. Twitter/X snowflake IDs and some database keys hit this — send them as strings. - Duplicate keys collapse to the last one:
{"a":1,"a":2}formats as{"a": 2}. Validators in other languages may reject the input instead. - Numeric-looking keys are reordered ahead of other keys because of how
JavaScript orders object properties.
{"b":1,"2":2,"a":3}comes back as{"2": 2, "b": 1, "a": 3}. - Number formatting normalizes:
1.0becomes1,1e3becomes1000,-0becomes0. - Escaped Unicode is decoded:
"\u00e9"is printed as"é". The meaning is identical; the bytes are not.
None of these are bugs, but they matter when you diff formatted output against the original — use the text diff tool on two formatted versions rather than on raw vs. formatted text.
Format vs. minify in practice
Minifying removes only whitespace outside strings, so savings depend on how
“pretty” the input was. A typical 4-space-indented API response shrinks by
20–40%; once gzip or Brotli is applied on the wire the difference drops to a
few percent, which is why most APIs do not bother minifying responses but do
avoid pretty-printing them. Where minified JSON really helps is inside HTML
attributes (data-config='{"a":1}'), inline <script type="application/json">
blocks, and localStorage, where there is no compression at all.
Related tools and snippets
- CSV ⇄ JSON converter — turn a spreadsheet export into an array of objects, or flatten JSON back to CSV.
- JWT decoder — the header and payload of a token are JSON; this decodes and pretty-prints them.
- Base64 encoder / decoder — JSON payloads are often shipped Base64-encoded inside other formats.
- Text diff — compare two formatted JSON documents line by line.
- Text and data tools overview — the full list of text utilities on WebTricks and how they fit together.
FAQ
Why does it say my JSON is invalid?
The usual culprits are trailing commas, single quotes, unquoted keys, comments, or NaN/Infinity/undefined — none of them are valid JSON. The error message comes from the browser's native parser and points at the offending token or position.
Is my data sent anywhere?
No. Parsing happens entirely in your browser with the native JSON.parse and JSON.stringify functions; nothing is uploaded or logged.
Does formatting change the order of my keys?
Object keys keep their original order, except that keys that look like array indexes ("0", "1", "42") are moved to the front in ascending order — that is how JavaScript objects work, not something the tool chooses.
Why did my 19-digit ID change?
JavaScript parses every JSON number as a 64-bit float, so integers above 9007199254740991 (2^53 - 1) lose precision. If you need exact large IDs, serialize them as strings on the server side.
What is the difference between Format and Minify?
Format re-indents the JSON with 2 or 4 spaces and one value per line for reading. Minify strips every byte of insignificant whitespace, which is what you want for request bodies and storage.
Can it format JSON with comments (JSONC) or JSON5?
No. Strict JSON has no comments, trailing commas or single quotes, so files like tsconfig.json or .eslintrc with comments will be rejected. Remove the comments first or use a JSONC-aware editor.