Developer guide
Fix a JSON unexpected token error
Unexpected token errors usually mean the parser found a character that is not allowed at that exact point in the JSON.
The problem
This often happens after copying an API response, editing a config by hand, or pasting JavaScript-style objects into a JSON-only parser.
Example
{
"status": "ok",
"count": 3,
}
{
"status": "ok",
"count": 3
}
How to fix it
- Read the error position first. If the parser reports a character offset, jump near that point and inspect the previous line too.
- Look for trailing commas, single quotes, missing quotes around keys, comments, or an extra closing bracket.
- After editing, validate the whole object again instead of checking only the line you changed.
Where to look first
Unexpected token errors are often reported a few characters after the real mistake. Check the line before the reported position, especially after a closing quote, closing bracket, or comma.
If the JSON came from a log line, remove timestamps, labels, and prefixes before validating. A parser only understands the JSON value itself, not the surrounding log text.
Common mistakes
- A comma after the last property in an object or array
- Using single quotes around a key or string value
- Pasting comments from a JavaScript config file
- Missing a quote before a string value
Related problems
FAQ
Why does the error mention an unexpected token?
The parser expected a valid JSON character at that position, but found something else, such as a comma, quote, bracket, or letter.
Is valid JavaScript object syntax always valid JSON?
No. JSON is stricter: keys and strings need double quotes, comments are not allowed, and trailing commas are invalid.
Should I format or validate first?
Validate first when the input is broken. Once it parses, formatting can make the structure easier to inspect.