json formatter
Errors named by line and column, not by character offset.
The short answer
Formatting means parsing the JSON and printing it again, so anything that comes back out is valid by construction. It also means an error is reported rather than tidied: a trailing comma or a single quote fails here exactly as it will fail in whatever was going to read the file.
Parses, then prints again, so whatever comes out is valid by construction. A trailing comma fails here exactly as it will fail in whatever was going to read the file.
The formula
parse → re-print with the indent you choose, or with none at all
Worked examples
- {"a":[1,2],"b":{"c":true}}
- 3 keys, valid
- A trailing comma
- reported, with the line
- Minify
- every space outside a string removed
Reference table
| Written as | Valid? | Why |
|---|---|---|
| {'a': 1} | No | Strings need double quotes |
| {"a": 1,} | No | No trailing commas, unlike JavaScript |
| // a comment | No | JSON has no comments at all |
| {a: 1} | No | Keys are strings, always quoted |
| NaN or Infinity | No | Numbers only, and finite ones |
How to use it
- 01Paste your JSONIt is checked as you type. Nothing is uploaded.
- 02Choose an indentTwo spaces, four, or minified with every optional space removed.
- 03Copy the resultOr read the error, which names the line rather than a character number.
Also searched for
Searches that land here include json formatter, json beautifier, json validator, format json online and minify json.
Formatting by parsing
Why it parses rather than reindents
A formatter that only moves whitespace will happily prettify a broken file, and you find out later. Parsing first means the output is JSON that a parser has already accepted. It also means the error arrives now, at the point where you can still see what you pasted.
Locating the error
Browsers report a character offset, which is no use in a four-hundred-line file. Where the parser gives a position, this page translates it into a line and column. Where the parser gives no position at all — and for some inputs V8 gives none — it says so instead of inventing one, because a confidently wrong line number costs more time than no line number.
What JSON does not have
No comments. No trailing commas. No single quotes. No unquoted keys. No NaN or Infinity. Every one of those exists in JavaScript, and every one of them is a common reason a config file will not load. JSON5 and JSONC exist to add them back, and neither is what a strict parser expects.
Questions people ask
Why is my JSON invalid when it looks fine?
Four things account for almost all of it: a trailing comma after the last item, single quotes instead of double, unquoted keys, and a comment. All four are legal JavaScript and none of them is legal JSON, which is why a file copied out of a source file so often fails.
What does minifying actually remove?
Every space, tab and newline that sits outside a string. Nothing inside a string is touched, so text keeps its formatting. On a large payload it typically saves a fifth of the bytes, though gzip closes most of that gap on anything served over HTTP.
Will formatting change my values?
Numbers are reprinted from their parsed value, so 1.50 comes back as 1.5 and 1e3 comes back as 1000. The value is identical; the spelling is not. Key order is preserved. Very large integers are the one real hazard: anything past 2^53 loses precision on the way through, which is why ids are best sent as strings.