Format, validate and minify JSON
Paste JSON to indent it for reading, check that it is valid, or strip the whitespace to make it as small as possible. When something is wrong, you get the browser's description of the error and where parsing stopped. Your data stays in your browser, which matters when it is an API response full of tokens and customer records.
The three buttons
- Format rewrites the JSON with two-space indentation and one value per line, so the structure is easy to follow.
- Minify removes every space and line break outside the strings. Use it for data you send or store, where only machines read it.
- Validate checks the syntax without changing anything.
Why JSON fails to validate
JSON is much stricter than the JavaScript it grew out of. Almost every error comes from one of these:
- A trailing comma after the last item, as in {"a": 1,}.
- Single quotes. Keys and strings need double quotes.
- Keys without quotes, such as {a: 1}.
- Comments. Neither // nor /* */ is allowed. Formats like JSON5 and the JSON-with-comments used by some editors accept them, but standard JSON does not.
- NaN, Infinity or undefined. They are not valid JSON values; use null or a number.
- A real line break or tab inside a string. Write it as \n or \t instead.
The error message points to where parsing stopped, and newer browsers add the line and column. The actual mistake is often just before that point, typically a missing comma at the end of the previous line.
What formatting can change
Formatting reads your JSON and writes it out again, so it can only keep what JavaScript can represent:
- Very large integers lose precision. Whole numbers above 9,007,199,254,740,991 cannot be stored exactly. A 64-bit ID such as 12345678901234567890 comes back as 12345678901234567000. If your data has IDs this long, they belong in strings.
- Duplicate keys collapse. If an object has the same key twice, only the last value is kept.
- Number-like keys move to the front. Keys such as "2" and "10" are listed first, in ascending order, because of how JavaScript orders object properties. Other keys keep their order.
None of this affects ordinary data, but check before you paste a formatted file back over the original.
Formatted or minified?
Indentation is for people. On a deeply nested file it can make up a large share of the size, which is why APIs and configuration stores usually keep JSON minified. If you are going to read it, format it; if a program is going to read it, minify it.