What this JSON formatter does
JSON is the lingua franca of the web: every REST API response, most config files (package.json, tsconfig.json, CI pipelines) and countless data exports use it. Servers almost always ship it minified — one endless line with every space stripped out — which is great for bandwidth and terrible for humans.
This tool does three jobs, entirely in your browser: pretty-print the JSON with 2- or 4-space indentation, minify it down to the smallest possible string, and validate it, pointing at the exact line and column of the first syntax error.
How to use it
- Paste your JSON into the input box.
- Pick an indentation width: 2 or 4 spaces.
- Click Format to pretty-print, Minify to compact, or Validate to just check it.
- If parsing fails, you get the engine’s original error message plus the line and column where it happened.
- Copy result sends the output to your clipboard; Clear resets everything.
How the line and column are calculated
When parsing fails, the JavaScript engine throws a SyntaxError that usually reports a character position, such as position 35. The validator counts the line breaks that appear before that position: the number of breaks plus one gives the line, and the distance from the last break gives the column.
Worked example
Take a small config file where someone forgot the comma after the port number:
- Line 1:
{"host": "localhost",— 21 characters, then a line break at position 21 - Line 2:
"port": 8080— 12 characters, then a line break at position 34 - Line 3:
"debug": true}
The parser reads 8080, then expects a comma or a closing brace — but instead finds the quote that starts "debug", at position 35. There are two line breaks before position 35 (at positions 21 and 34), so the error sits on line 3, and 35 minus 34 gives column 1. Add the missing comma after 8080 and the indicator flips from red to green.
JSON vs JavaScript object literals
JSON borrows JavaScript’s syntax but keeps only a strict subset. This table explains most “but it works in my code!” surprises:
| Feature | JSON | JavaScript literal |
|---|---|---|
| Keys | double quotes required | quotes optional |
| Single-quoted strings | not allowed | allowed |
| Trailing commas | not allowed | allowed |
| Comments | not allowed | allowed |
undefined, NaN, Infinity | not allowed | allowed |
| Dates, functions | not supported | supported |
The four most common validation failures map straight onto that table: single quotes, a trailing comma, unquoted keys, and comments. If your snippet came from a JavaScript file, expect to fix at least one of them.
Your data never leaves the browser
Parsing, formatting and minifying all happen locally with JavaScript on your device — nothing is uploaded, logged or stored. That matters when the JSON holds API keys, bearer tokens, customer records or anything else you would not paste into a stranger’s server. Here there is no upload at all: close the tab and the data is gone.
Frequently asked questions
Why is my JSON invalid if it runs fine in JavaScript?
Because JSON is a strict subset of JavaScript syntax. A JavaScript object literal tolerates single quotes, unquoted keys, trailing commas, comments and values like undefined; strict JSON rejects every one of those. Code copied straight out of a .js file usually needs double quotes around all keys before it validates.
Can I add comments to a JSON file?
No — the specification deliberately leaves them out, and a stray // note is one of the most common reasons validation fails. Common workarounds: add a descriptive key such as "_comment" inside the object, keep documentation in a separate file, or switch to JSONC or JSON5 where your tooling supports them.
Should I indent with 2 or 4 spaces?
Both are valid — it is purely a readability convention. Two spaces dominates the JavaScript and Node.js world; four spaces is more common in Python and .NET shops. For anything transmitted over the network, minify instead: indentation is pure extra weight.
What are JSON5 and JSONC?
They are relaxed supersets of JSON. JSONC (JSON with Comments) powers VS Code’s settings files; JSON5 additionally allows single quotes, trailing commas and unquoted keys. Standard JSON.parse accepts neither, and neither do most APIs — so if a service rejects your payload, validate it here against the strict standard first.