How to use the JSON Formatter
- Paste JSON into the “JSON input” box, or click “Load sample” to try it.
- Choose “Beautify” and an indentation (2 spaces, 4 spaces or Tab), or choose “Minify” to remove all whitespace.
- Tick “Sort keys” to order object keys alphabetically, which makes two JSON files much easier to compare.
- Click “Copy output” or “Download .json”. If the JSON is invalid, fix the line shown under the input and the output updates automatically.
The JSON errors you will hit most often
JSON (RFC 8259) is much stricter than JavaScript. The usual suspects are a trailing comma after the last item ({"a": 1,}), keys or strings in single quotes, unquoted keys ({name: "x"}), comments, and values such as NaN, Infinity or undefined, none of which are valid JSON.
Browsers report these differently. Chrome says “Unexpected token } in JSON at position 42”, Firefox gives a line and column, and Safari often gives no position at all. This tool runs its own strict scanner, so you always get the line, the column and a caret pointing at the problem, whichever browser you use.
Beautify vs minify
Beautifying (pretty-printing) adds line breaks and indentation so people can read the structure. Two spaces is the default in most JavaScript and TypeScript projects and in tools like Prettier; four spaces matches Python’s json.dumps(indent=4) and many Java and C# codebases.
Minifying removes every unnecessary space and line break. It is what you send over the network or store in a config value, and it typically shrinks pretty-printed JSON by 20% to 40%. The status line shows the size before and after so you can see the difference.
Why sorting keys helps
Object keys in JSON have no meaningful order, but APIs and serializers often emit them in different orders, which turns a simple comparison into noise. Sorting keys recursively gives a canonical form: run both documents through the formatter with “Sort keys” on, then diff the output. Array order is kept, because it is significant.
Large numbers and other things to watch
JavaScript numbers are 64-bit floats, so integers above 9,007,199,254,740,991 (2^53 − 1) lose precision when parsed. Twitter/X and many databases send 64-bit IDs as strings for exactly this reason. If a long ID changes after formatting, the source should be sending it as a string.
Duplicate keys are technically allowed by the spec, but most parsers keep only the last value, so the formatted output will show just one of them.
Frequently asked questions
Is my JSON sent to a server?
No. Parsing, validation and formatting all happen in your browser, so it is safe to paste API responses or config files that contain tokens. Only your mode and indentation choices are remembered on your device.
Why does it say a trailing comma is not allowed?
JavaScript and many config formats accept a comma after the last item, but strict JSON does not. Remove the comma before the closing } or ].
Can it format JSON with comments (JSONC) like tsconfig.json?
No. Comments are not part of JSON, so the validator flags them. Remove the // or /* */ comments first, or use a JSONC-aware editor such as VS Code for those files.
What is the difference between a JSON formatter and a JSON validator?
A validator only tells you whether the text is valid JSON; a formatter rewrites it with consistent indentation. This tool does both: invalid input gets an error with its position, valid input gets formatted.
How large a file can it handle?
Several megabytes are fine on a modern computer. Very large files (tens of MB) may make the page slow, because everything runs in your browser.
Does sorting keys change my data?
No. Only the order of keys inside objects changes, which has no meaning in JSON. Values and the order of array items stay exactly the same.
Last updated: View source code