JSON Formatter and Validator

Format, minify and check JSON, with errors located by line and column. Nothing is uploaded.

JSON
Result

The four things that usually break JSON

JSON is a much smaller language than JavaScript, and almost every validation failure comes from writing JavaScript by habit.

WrittenProblemCorrect
{"a": 1,}Trailing comma after the last item{"a": 1}
{'a': 1}Single quotes; JSON strings need double{"a": 1}
{a: 1}Unquoted key{"a": 1}
{"a": 1} // noteJSON has no comment syntax at allRemove it, or move it into a field

Two more catch people out. NaN and Infinity are not valid JSON numbers even though JavaScript accepts them, and a number may not have a leading zero or a leading plus sign.

Errors are located, not just reported

A browser's own parse error says only how far into the string it got, which is useless in a file of any size. The position is converted here into a line and column and the offending line is quoted back, so the fix is usually obvious from the message alone.

Sorting keys, and when not to

Object keys have no defined order in JSON, so sorting them produces an equivalent document: nothing about the data changes. It is genuinely useful when comparing two files that differ only in the order their keys were written, which otherwise shows up as a diff on every line.

It does change the bytes, though. Where a checksum, a signature or a cache key is computed over the text of the document, sorting will invalidate it. Leave the option off in that case.

JSON Lines

A JSON Lines file holds one complete JSON document per line rather than a single array. Log pipelines and data exports use it because a reader can handle one record at a time without holding the whole file in memory. Feeding such a file to an ordinary parser fails on the second line, which is a confusing error if you were not expecting the format.

With the JSON Lines option on, each line is parsed separately, formatting is applied per line, and a failure names the line number that broke rather than an offset into the whole file.

How to use it

Paste and press Format, Minify or Validate only. Formatting reflows the document at the indent you choose; minifying strips every optional space, which is what you want before embedding JSON in something else. Validate reports what it found without producing output, which is the quickest way to check a file you do not want to alter.

Questions

Why is my JSON invalid when it looks fine?

The three usual causes are a trailing comma after the last item, single quotes instead of double quotes, and unquoted keys. All three are legal in JavaScript and none is legal in JSON. A comment is the fourth: JSON has no comment syntax at all.

Is my JSON uploaded anywhere?

No. Parsing and formatting happen inside your browser and this tool has no backend. That matters here more than on most tools, because the JSON people paste into a formatter is very often a configuration file or an API response containing keys and tokens.

What does sorting keys do to my data?

Nothing, in JSON terms. Object keys have no defined order in the format, so sorting them produces an equivalent document. It is useful for comparing two files that differ only in key order, and it does change the byte output, so avoid it where a checksum or a signature is calculated over the text.

Can it handle very large files?

Up to a few megabytes comfortably. The whole document is parsed into memory, so a very large file will make the browser tab work hard. Anything of that size is better handled by a streaming parser at the command line than by a web page.

What is JSON Lines?

A format where each line is a separate JSON document rather than the file being one array. Logs and data exports commonly use it because a reader can process one line at a time. The JSON Lines option here parses each line separately and reports which line failed.