How to find and fix invalid JSON
By Priyabrata Saha · Published 4 November 2026
Short answer
Most invalid JSON comes from writing it like JavaScript: trailing commas, single quotes, comments or unquoted keys. Paste it into a validator to get the line and column of the first error, fix that, and validate again until it passes.
JSON is stricter than it looks
JSON looks like a JavaScript object, but the specification, RFC 8259, is much stricter. Many configuration files and code snippets are written in a relaxed style that JavaScript accepts and a JSON parser rejects. That gap causes most “invalid JSON” errors.
The usual suspects
- A trailing comma after the last item: {"a": 1,}. Remove the comma.
- Single quotes: {'name': 'Ada'}. Strings and keys must use double quotes.
- Unquoted keys: {name: "Ada"}. Every key must be a quoted string.
- Comments: // or /* */ are not part of JSON. Remove them, or use a format that allows them, such as JSON5 or YAML.
- Special values: undefined, NaN and Infinity are not valid. Use null or a number.
- Unescaped characters: a line break or tab inside a string must be written as \n or \t.
Reading the error position
A parser stops at the first character it cannot accept and reports where that is. The position is where it gave up, which is often just after the real mistake. For a trailing comma, the error points at the closing brace on the next line, because that is where the parser expected another key.
JSON Validator converts the position into a line and column and shows the surrounding text. The wording of the error message comes from your browser, so Chrome, Firefox and Safari phrase it differently; the line and column are what to rely on.
Fixing one error at a time
Only the first error can be reported reliably, because everything after it may be misread. Fix that one, validate again, and repeat. In a large file it often helps to format it first: once each value is on its own line, the reported line number points straight at the problem.
Large numbers and duplicate keys
JavaScript numbers lose precision above 9,007,199,254,740,991. A tool that parses and re-serialises JSON would quietly turn 9007199254740993 into 9007199254740992, which corrupts IDs from databases and APIs. JSON Formatter and JSON Minifier change only whitespace and copy number digits exactly as written.
Duplicate keys, such as two "id" members in one object, are valid syntax but ambiguous: most parsers keep the last one. They are kept as written in the formatted output, so look for them if a value seems to vanish after parsing elsewhere.
Valid is not the same as correct
A validator checks syntax only. It cannot tell you that a required field is missing, that a port is a string instead of a number, or that a date is in the wrong format. For that you need a JSON Schema and a schema validator in your own build or test pipeline.