Useful Hacks

JSON parse errors explained: 'Unexpected token', 'Expected comma or brace', and the rest

Useful Hacks Team·

JSON Validator

Validate JSON syntax and pinpoint errors instantly.

Open JSON Validator

JSON parse errors are terse and often point at a character offset instead of a line. Here's what the common ones mean and how to find the spot fast.

Why the message is confusing

A strict parser reports the first place the text stops being valid JSON — not necessarily where you made the mistake. A missing comma on line 5 is often reported as an "unexpected" token on line 6, because that's where the parser first can't continue. Read the line *before* the reported one too.

"Unexpected token" and "Unexpected end of input"

Unexpected token X — the parser found a character it didn't expect: a bare word that isn't true, false or null; a single quote; a stray bracket. Usually a missing quote around a key or string, or a missing comma.

Unexpected end of input — the document ended while something was still open. Count your brackets and braces; one is unclosed. It's also what you get from empty input.

"Expected ',' or '}'"

Inside an object, after a "key": value pair, JSON expects either a comma (another pair follows) or a closing brace (the object ends). This error means it got something else — typically a missing comma between two pairs, or a trailing comma before the }.

"Bad string" and "Bad escaped character"

A string contains a raw newline or tab (they must be written as \n / \t), or a backslash followed by a character that isn't a valid escape. Invalid \u sequences — not four hex digits — fall here too.

Trailing commas and single quotes

["a", "b",] and {'key': 'value'} are valid JavaScript but invalid JSON. Standard parsers reject both. If your source has them on purpose — a config file, a copied object literal — a repair step can convert them, but that's a deliberate transformation, not validation.

Finding it fast with line and column

The raw position 42 in a parser message is a character offset from the start of the string, which is painful to locate by eye. A good validator converts it to a line and column and marks the spot in the editor. Paste your JSON into the JSON Validator or the JSON Viewer & Formatter — both show the line, column and a plain-language hint, and the formatter's Repair step handles trailing commas and single quotes once you've seen where they are. To browse the structure afterwards, see how to read JSON with a tree viewer.

Frequently asked questions

What does 'Unexpected token in JSON' mean?
The parser hit a character it didn't expect — often a missing comma, a missing quote around a key or string, or a single quote where a double quote is required. Check the reported line and the one before it.
What does 'Expected comma or closing brace' mean?
Inside an object, after a key/value pair JSON expects a comma or a closing brace. This usually means a missing comma between two pairs, or a trailing comma before the closing brace.
How do I find the error in a large JSON file?
Use a validator that reports line and column instead of a raw character offset, and marks the location in the editor. The parser's 'position N' is a character count from the start of the file, which is hard to locate by eye.
Are trailing commas allowed in JSON?
No. Trailing commas and single-quoted strings are valid JavaScript but invalid JSON. A repair tool can convert them, but strict validation will always flag them.

Related guides

JSON Validator

Validate JSON syntax and pinpoint errors instantly.

Open JSON Validator

Search tools

Search for any tool by name, category or keyword