Fix: Unexpected Token in JSON
The Unexpected token error is the most common JSON parsing error. It means the parser hit a character it did not expect — usually a minor syntax mistake that is easy to fix once you know where to look.
What Does "Unexpected Token" Mean?
JSON parsers read your string character by character following a strict grammar defined in RFC 8259. When the parser encounters a character that does not belong at that position in the grammar, it throws an "Unexpected token" error and stops parsing immediately.
The error typically looks like one of these in different environments:
// JavaScript (V8)
SyntaxError: Unexpected token ',' in JSON at position 42
// Python
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 3 column 5
// Go
invalid character ',' after object keyCommon Causes
1. Trailing Commas
The most frequent cause. JSON does not allow a comma after the last element in an array or object.
Invalid
{
"name": "Alice",
"age": 30, ← trailing comma
}Valid
{
"name": "Alice",
"age": 30
}2. Single Quotes Instead of Double Quotes
Invalid
{'name': 'Alice'}Valid
{"name": "Alice"}3. Unquoted Object Keys
Invalid
{name: "Alice"}Valid
{"name": "Alice"}4. Comments in JSON
JSON does not support // line comments or /* block comments */.
Invalid
{
// user info
"name": "Alice"
}Valid
{
"name": "Alice"
}5. undefined, NaN, or Infinity Values
These JavaScript-specific values are not part of the JSON specification.
Invalid
{"score": NaN, "limit": Infinity}Valid
{"score": null, "limit": null}Reference: What Is and Is Not Valid JSON
| Feature | Valid in JSON? | Alternative |
|---|---|---|
| Trailing comma | No | Remove it |
| Single-quoted strings | No | Use double quotes "…" |
| Unquoted keys | No | Use "key": value |
| // or /* */ comments | No | Remove or use JSONC |
| undefined | No | Use null or omit the key |
| NaN | No | Use null |
| Infinity | No | Use null or a large number |
| null | Yes | — |
| true / false | Yes | — |
| Numbers (int & float) | Yes | — |
| Nested objects & arrays | Yes | — |
Fix It Now — Paste Your JSON Below
The formatter below parses your JSON and highlights the exact error line. Fix the issue interactively before copying it back.
Frequently Asked Questions
What does 'Unexpected token' mean in JSON?▾
It means the JSON parser encountered a character it did not expect at that position. Common culprits are trailing commas, single-quoted strings, unquoted keys, JavaScript comments, or values like undefined and NaN that are not valid in JSON.
Can JSON have trailing commas?▾
No. The JSON specification (RFC 8259) does not allow trailing commas after the last item in an array or object. JavaScript itself allows them in object literals, which is why developers often mistakenly add them to JSON.
Why does JSON require double quotes instead of single quotes?▾
The JSON standard explicitly requires double quotes for strings and object keys. Single quotes are valid JavaScript but invalid JSON. Always use double quotes when writing JSON.
Can I add comments to JSON?▾
No. Standard JSON does not support comments. If you need annotated configuration files, consider JSONC (JSON with Comments) or YAML instead, but be aware that these are not interchangeable with standard JSON parsers.
How do I quickly find which line has the unexpected token?▾
Paste your JSON into the formatter on this page — it highlights the exact error line. Most browser DevTools consoles also include a position number in the error message that you can map to a line.
More JSON error fixes
See our other error fix guides below.
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.