Why your JSON is invalid: 7 rules that trip people up
JSON is a subset of JavaScript’s object syntax, which is exactly why it surprises people. Code you
would happily paste into a .js file is often rejected by a JSON parser. The error is almost always
one of these seven things.
1. Trailing commas
The most common cause by a wide margin. JSON forbids a comma before a closing bracket or brace.
{
"name": "Tools",
"tags": ["json", "formatter",],
}
Both highlighted commas are legal in JavaScript and illegal in JSON. Remove the one after
"formatter" and the one after the array.
2. Single quotes
String delimiters must be double quotes, on both keys and values.
{ 'name': 'Tools' }
3. Unquoted keys
{ name: "Tools" } is a valid JavaScript literal and invalid JSON. Every key needs double quotes.
4. Comments
There is no comment syntax in JSON. // and /* */ both fail. If a config file needs comments,
that file is JSON5, JSONC or YAML — not JSON — and a strict parser will reject it. The usual
workaround is to move the note into a field such as "_comment".
5. NaN, Infinity and undefined
JSON has no representation for these. Write null instead, or quote the value if it is really a
label. This shows up constantly when a JavaScript object is dumped with a naive serializer.
6. Numbers that are not numbers
Leading zeros (007) and a bare dot (.5) are invalid; 0.5 and 7 are fine. A value that looks
like a date, 2026-09-28, is invalid too — it must be a quoted string, because bare dates are not
a JSON type at all.
7. Unescaped control characters
A literal newline inside a string is not allowed; it has to be written as \n. The same applies to
a raw tab. Separately, a file saved with a UTF-8 byte order mark can fail on the very first
character even though the text looks perfect — save as UTF-8 without BOM.
Finding the position
Parser messages differ, but they all give an offset you can convert into a place in the document:
SyntaxError: Expected ',' or '}' after property value in JSON at position 812(V8)Unexpected token < in JSON at position 0— this one almost always means you are parsing an HTML error page instead of an API response. Check the status code before the body.- Python reports
line 4 column 12 (char 88)directly.
The JSON formatter runs the parse in your browser and shows the line and column of the failure, which is usually enough to spot a stray comma without counting.
Two things that look like errors but are not
Duplicate keys are valid JSON. The document parses, and most parsers silently keep the last value, which is how “my config change disappeared” bugs happen.
Deeply nested or very large documents are also valid; a stack overflow while parsing is a limit of the parser, not a problem with your data.