How to Format and Validate JSON
JSON is a text format for data. A single missing quote or comma makes the whole document invalid, so a formatter that points to the error saves time.
The most common JSON errors
- Trailing comma.
{"a":1,}is invalid. Remove the last comma. - Single quotes. JSON requires double quotes around keys and strings.
- Unquoted keys.
{a:1}is valid JavaScript but not valid JSON. - Comments. JSON does not allow // or /* */ comments.
- Special values. NaN, Infinity and undefined are not valid JSON.
Pretty print and minify
Pretty printing adds indentation so people can read it. Minifying removes whitespace to make the file smaller for sending over a network.
Tip
Paste your JSON into the formatter. If it is valid you get a clean indented version. If not, the error message shows where parsing failed. Your data stays in your browser.
Advertisement