Data · 3 min read ·
Invalid JSON? The 7 mistakes behind almost every error
Trailing commas, single quotes, comments and more: the small slips that break JSON, how to spot them quickly and how to fix each one.

“Unexpected token” and “Unexpected end of JSON input” are among the errors developers see most often. JSON is a strict format, much stricter than the JavaScript it came from, and almost every failure comes down to one of a handful of mistakes.
1. A trailing comma
A comma after the last item of an object or array is the number one error. JavaScript accepts it; the JSON standard does not.
{"name": "Ana", "age": 31,} ✗
{"name": "Ana", "age": 31} ✓
2. Single quotes and 3. unquoted keys
Every key and every string must use double quotes. {name: 'Ana'} is valid JavaScript but invalid JSON; it has to be {"name": "Ana"}.
4. Comments
JSON has no comments. // and /* */ are errors, which surprises anyone copying from a config file written in JSON5 or JSONC, such as VS Code settings.
5. Special values and 6. unescaped characters
undefined, NaN, Infinity and functions don’t exist in JSON; use null or a number instead. Inside strings, a double quote must be written as \" and a backslash as \\, and a line break as \n. Windows paths are a classic trap: "C:\new" contains a newline escape, not a backslash followed by n.
7. Missing or extra brackets
A missing closing } or ] usually shows up as an error at the very end of the input, far from the real mistake. Formatting the JSON with indentation makes the broken level easy to see.
Errors that are hard to see
Some invalid JSON looks perfectly fine on screen:
- Curly quotes. Text copied from a word processor, a chat app or a slide often has “ and ” instead of straight double quotes. They look almost the same, but JSON accepts only the straight " character.
- A byte order mark (BOM). Some Windows editors save files with an invisible character at the start. JavaScript’s JSON.parse and Python’s json.loads both reject it, and the error points at position 0.
- Non-breaking spaces and other invisible characters pasted from web pages.
Valid JSON that still causes bugs
Python’s json.dumps writes NaN and Infinity by default, which other parsers reject; pass allow_nan=False to catch it early. Very large integers, such as 64-bit database IDs, are valid JSON but lose precision in JavaScript beyond 9007199254740991, so APIs often send them as strings. Duplicate keys are allowed by most parsers, but the last value silently wins.
How to read the error message
Parsers report where they gave up, not where you made the mistake. A missing comma is usually reported at the start of the next key, and a missing closing bracket at the very end of the input. Look just before the reported position.
{
"name": "Ana"
"age": 31 ← error reported here (line 3)
} the missing comma is at the end of line 2
Find the exact spot
The 4Dev JSON Validator checks your text against the JSON standard (RFC 8259) and reports the line and column of the first error, plus a suggested fix. It checks syntax, not meaning: valid JSON can still have a wrong type or a missing field for your application.