Unexpected token means the parser reached a character that should not appear at that point in valid JSON.
You may see this in JSON.parse, API debugging, config imports, or validation tools. The character in the message matters: Unexpected token }, Unexpected token o, and Unexpected token < usually point to different root causes.
The Most Common Cause: A Trailing Comma
{
"name": "Tom",
"age": 18,
}Standard JSON does not allow a comma after the final object property or array item.
{
"name": "Tom",
"age": 18
}What Different Tokens Often Mean
| Error message | Common cause | How to fix it |
|---|---|---|
| Unexpected token } | Trailing comma or missing value | Check object and array endings |
| Unexpected token o | Parsing an object again as JSON text | Make sure JSON.parse receives a string |
| Unexpected token < | The response is HTML | Check the API URL, auth state, or server error page |
| Unexpected token / | The JSON contains comments | Remove line or block comments |
| Unexpected token n | Python-style None | Use JSON null instead |
A Practical Debugging Order
- Confirm the content is JSON, not HTML, logs, or plain text.
- Check for comments, trailing commas, single quotes, and unquoted keys.
- Look for Python-style True, False, or None values.
- If it came from an API, inspect the HTTP status code and response headers.
- Format the fixed JSON to confirm the structure is complete.
Summary
Unexpected token is not one single bug. It is a parser signal. Start with the reported character, then verify the source data and syntax rules.