How to format, validate and fix JSON
Read and debug JSON quickly — pretty-print it, find the exact line of a syntax error, understand the most common mistakes and minify it for production.
· 1 min read
JSON is the lingua franca of APIs and configuration files. It's also strict: a single misplaced comma makes the whole document invalid.
Make it readable
Paste minified JSON into the JSON formatter to get indented, multi-line output. Turning on Sort keys orders object keys alphabetically at every level, which makes two versions of a document easy to compare with Text compare.
Find the error
The JSON validator reports the exact line and column of the first error and shows a caret under it. The usual suspects:
| Mistake | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1,} |
{"a": 1} |
| Single quotes | {'a': 1} |
{"a": 1} |
| Unquoted key | {a: 1} |
{"a": 1} |
| Comment | {"a": 1 // note} |
not allowed |
| Special numbers | NaN, Infinity |
use null or a string |
JavaScript object literals accept all of the invalid forms, which is why copying an object from code into a .json file often fails.
Minify for production
JSON minifier removes all whitespace outside strings. It typically saves 10–30% on indented files; gzip or Brotli compression on your server will save far more on top.
Convert to and from spreadsheets
Need to hand data to a non-developer? JSON to CSV flattens nested objects into columns like address.city, and CSV to JSON goes the other way, turning numbers and booleans into proper JSON types.
Is it safe to paste API responses?
These tools run entirely in your browser, so production data isn't transmitted. As a habit, still redact tokens and personal data before sharing JSON with anyone.
Tools used in this guide
- JSON FormatterBeautify JSON with indentation and optional key sorting.
- JSON ValidatorCheck JSON syntax and pinpoint errors by line and column.
- JSON MinifierRemove whitespace from JSON and see the size saved.
- CSV to JSON ConverterConvert CSV rows into a JSON array of objects.
- JSON to CSV ConverterConvert JSON arrays into CSV for spreadsheets.