How to Format and Validate JSON (and Fix the Common Errors)
2026-08-08
JSON almost never arrives formatted. An API returns forty kilobytes on one line, a log entry is copied out of a terminal, or a config file has been edited by three people using three different editors. The first step to understanding it is making it readable.
Step by step
- Open the JSON Formatter & Validator.
- Paste your JSON into the box.
- Choose two-space, four-space or minified output.
- Copy the result, or download it as a .json file.
The four errors that cause almost everything
- Trailing commas.
[1, 2, 3,]is valid JavaScript and invalid JSON. This is the single most common cause. - Single quotes. JSON strings must use double quotes.
{'a': 1}fails. - Unquoted keys.
{a: 1}is a JavaScript object literal, not JSON. Keys are always quoted strings. - Comments. JSON has none.
//and/* */belong to JSON5 and JSONC, which most parsers will reject.
When validation fails you get the parser's own message, which names the character position. Jump to that position and one of the four above is usually sitting there.
Sorting keys for readable diffs
JSON objects are unordered by definition, but JSON.stringify preserves insertion order — which means two files with identical data can produce a diff hundreds of lines long. Sorting keys alphabetically before comparing turns that into a diff that shows only real changes.
Minifying for production
Minified output removes every space and line break outside strings. The data is identical and the payload is smaller, which is what you want in an API response or a config shipped to browsers. Keep the formatted version in source control and minify at build time.
Everything runs in your browser, so you can paste a production API response containing customer records or access tokens without it travelling anywhere.