View My JSON
Skip to main content
Blog

How to fix invalid JSON: the seven errors you will actually see

Fix invalid JSON step by step: trailing commas, single quotes, unquoted keys, comments, missing brackets, NaN and undefined, and BOM problems, with examples.

A JSON parser is strict by design. It accepts exactly the grammar in RFC 8259 and nothing else, so one stray comma anywhere in a 5,000-line file makes the whole document invalid. The good news is that the same few mistakes account for nearly all of the failures I see: trailing commas, single quotes, unquoted keys, comments, a missing bracket, values that JSON does not have, and an invisible byte at the start of the file. This post goes through each one with the broken text, the error you will typically get, and the fix. Error wording differs between engines, so I show the common shape and not an exact string to match.

Sources and further reading

Try the JSON workspace