How to use the JSON formatter
- Paste your JSON into the input box, or press Sample to try it.
- Choose Format or Minify. Format adds line breaks and indentation; Minify removes every unnecessary space.
- Pick the indentation: 2 spaces (the most common), 4 spaces or tabs.
- Turn on Sort keys to order every object’s keys from A to Z, which makes two files easy to compare.
- Keep “Fix comments and trailing commas” on if you paste from config files.
- Copy or download the result as a
.jsonfile.
If the JSON is invalid, the output panel shows the error instead: the line and column, what went wrong, and the line itself with a caret (^) under the problem.
How the validator works
The tool has its own parser instead of relying on the browser’s JSON.parse. Browsers report errors in different ways, and some only give a character offset. Reading the text character by character means every error can be described precisely and the same way in every browser. It follows RFC 8259:
- objects use
{ }with double-quoted keys, arrays use[ ]; - strings use double quotes and only these escapes:
\" \\ \/ \b \f \n \r \t \uXXXX; - numbers have no leading zeros, no leading
+, and noNaNorInfinity; - the only literal words are
true,falseandnull.
Duplicate keys are recorded with their full path (for example $.settings.theme) so you can find them in large files.
Worked examples
Example 1: an API response on one line
Paste a minified response such as {"id":7,"tags":["a","b"],"owner":{"name":"Ana"}}. Format it with 2 spaces and nested objects become readable in seconds. The statistics line shows keys, objects, arrays and depth, which helps when you’re writing types or a schema for the response.
Example 2: a config file with comments
A tsconfig.json or VS Code settings file often contains // comments and a trailing comma after the last property. With the fix option on, both are removed (strings such as URLs containing // stay intact) and you get strict JSON that any parser accepts. A note under the output lists what was changed.
Example 3: finding a missing comma
Paste a hand-edited file where one line is missing its comma. The error appears as Line 14, column 3: unexpected character “ with the offending line shown beneath it. The parser stops at the first error, so fix that and the next one (if any) is shown.
Formatting vs minifying
Formatted JSON is for people: code reviews, documentation and debugging. Minified JSON is for machines: it removes whitespace and typically saves 10–30% before compression. With gzip or Brotli on the server, the difference shrinks further, so minify mainly for storage, query strings or embedded data.
Common mistakes
- Single quotes.
{'a': 1}is JavaScript, not JSON. Use double quotes. - Unquoted keys.
{a: 1}fails; write{"a": 1}. - Comments in production JSON. Many parsers reject them; strip them before shipping.
- Large numbers. JSON allows any size of number, but JavaScript loses precision above 2⁵³. Send IDs as strings.
- Pasting smart quotes. Word processors replace
"with “ ”, which JSON doesn’t accept.