Guide

How to validate and format JSON without losing the data

A practical way to read a JSON error, fix the first problem, and format the document only after it parses.

JSON is a small data format. A formatter cannot repair it until a parser accepts it. Start with the error the parser names, because later errors are often a consequence of the first one.

Read the first error

Paste the document into the JSON Formatter & Validator. If the status line names a position, look there first. A common failure is a trailing comma after the last object field or array item. JSON does not allow it. Another is a string wrapped in single quotes. JSON strings use double quotes.

Comments are also rejected. If the text came from a JavaScript file, remove the comments or convert the file to JSON before you format it.

Format after it parses

Choose two or four spaces and format. Formatting rewrites whitespace. It should not rename keys or change a number into a string. If a very large integer changes, the limit is the JSON number parser, not the indent. Keep those values as strings if every digit matters.

When you need a table

If the value is an array of flat objects, the JSON to CSV converter can make a spreadsheet file. It refuses nested values instead of dropping them. That refusal is the useful part: you can see which field would have lost structure.