Common JSON Syntax Errors and How to Fix Them
JSON looks close enough to a JavaScript object literal that it's easy to write something a validator rejects without realizing why. The JSON grammar in RFC 8259 is stricter than it looks — here are the errors that show up most often, each with the broken form and the fix.
1. Trailing comma
JSON's grammar has no rule allowing a comma after the last member of an object or array — even though many editors and languages tolerate it.
Invalid
{"a": 1, "b": 2,}Fixed
{"a": 1, "b": 2}2. Unquoted or single-quoted keys
Object keys must always be double-quoted strings. Single quotes and bare identifiers are valid in JavaScript object literals, not in JSON.
Invalid
{name: 'Ann'}Fixed
{"name": "Ann"}3. Comments
JSON has no comment syntax at all. Formats like JSON5 or JSONC add comments as an extension, but a comment must be stripped before a standard JSON parser will accept the text.
Invalid
{
// user record
"name": "Ann"
}Fixed
{
"name": "Ann"
}4. Wrong-case literals
JSON literals are case-sensitive — only lowercase true, false, and nullare valid. Python's capitalized True/None is a frequent source of this when copying values out of a Python dict.
Invalid
{"active": True, "deleted": None}Fixed
{"active": true, "deleted": null}5. Unescaped backslashes in strings
A backslash starts an escape sequence inside a JSON string. A lone backslash before a character that isn't part of a recognized escape (like a Windows path separator) is invalid — it must be doubled.
Invalid
{"path": "C:\Users\ann"}Fixed
{"path": "C:\\Users\\ann"}6. Leading zeros or a leading plus sign
JSON numbers can't have leading zeros (other than a lone 0) or an explicit + sign, unlike some programming-language number literals.
Invalid
{"id": 007, "score": +5}Fixed
{"id": 7, "score": 5}7. Mismatched or missing brackets
Every [ needs a matching ], and every { needs a matching }. This one is easy to miss in deeply nested structures.
Invalid
{"items": ["a", "b"}Fixed
{"items": ["a", "b"]}These are all syntax problems — the text itself doesn't parse. Once your JSON is syntactically valid, checking whether it has the right fields and types is a separate step; see the JSON Schema guide for that. To catch syntax errors like the ones above automatically, with a line and column pointing at the problem, use the JSON validator.
JSON Syntax Errors FAQ
- Why does my JSON work in JavaScript but fail a JSON validator?
- A JavaScript object literal allows unquoted keys, single quotes, comments, and (in modern engines) a trailing comma — none of which are valid in JSON itself. JSON is stricter than the JS syntax it resembles.
- Does JSON support comments?
- No. The JSON grammar (RFC 8259) has no comment syntax. Formats like JSON5 or JSONC add comments, but they must be stripped before parsing with a standard JSON parser.
- Are duplicate keys in a JSON object an error?
- RFC 8259 leaves the behavior undefined rather than banning it outright — most parsers silently keep the last value and drop earlier ones, which can hide bugs even when no error is raised.
- How do I find exactly which line has the error?
- Paste the JSON into the JSON validator — it reports an approximate line and column for the first syntax problem so you can jump straight to it.