ERROR - Updated 2026-06-25
JSON Unexpected token Error
How to debug JSON Unexpected token errors by checking the token, position, quotes, commas, and real API response body.
Open JSON Formatter & Error CheckerQuick Answer
JSON Unexpected token means the parser found a character that is not valid at that point in JSON. The problem may be a trailing comma, single quotes, a missing brace, an already-parsed object, or an API response that is not JSON at all. Check the token and position first, then inspect the exact string being parsed.
Why This Matters
JSON parse errors often appear in front-end code, API integrations, webhooks, and configuration files. The error message can feel vague, but the token and position usually point to a small area. Guessing without checking the real response body wastes time.
Common Causes
| Error Shape | Likely Cause | First Check |
|---|---|---|
Unexpected token } | Trailing comma or missing value | Character before } |
| `Unexpected token '`` | Single quotes | Use double quotes in JSON |
Unexpected token o | Parsing an object again | Check the value type |
Unexpected token < | HTML returned instead of JSON | Response status and body |
Practical Workflow
- Copy the exact input passed to
JSON.parse()orresponse.json(). - Paste it into JSON Error Doctor.
- Check the token and position.
- If it came from an API, inspect status code, Content-Type, and response body.
- Fix syntax only after confirming the response is actually JSON.
Debug Checklist
| Check | Why it matters | What to do |
|---|---|---|
| Exact input | Console previews can hide the real string. | Log or copy the raw text before parsing. |
| First character | <, H, or [ changes the likely cause. | Inspect the first 200 characters before editing. |
| Line and column | JSON syntax errors usually point near the broken character. | Check the character before the reported position too. |
| Response metadata | API errors often return HTML or text with a JSON-looking status. | Review status code, URL, redirect, and Content-Type. |
| Data type | Parsing an object again can create misleading token errors. | Confirm whether the value is already parsed. |
Example
Invalid JSON:
{
"name": "Alice",
}
Valid JSON:
{
"name": "Alice"
}
The trailing comma is legal in some JavaScript object literals, but not in JSON.
Common Mistakes
- Copying a console object instead of the real response text.
- Calling
JSON.parse()on data that is already an object. - Fixing JSON syntax while the API is returning an HTML login page.
- Ignoring the position number in the error message.
Practical FAQ
Does Unexpected token always mean my JSON syntax is wrong?
No. It can be JSON syntax, but it can also mean the value is not JSON at all. API responses, HTML error pages, redirects, and already-parsed objects are common causes.
Why does Unexpected token o happen?
It often appears when code calls JSON.parse() on an object instead of a JSON string. Check typeof value before parsing.
Should I format the JSON first or inspect the API response first?
If the data came from an API, inspect the response status, Content-Type, and first characters first. Formatting only helps after you know the body is meant to be JSON.
Are trailing commas valid JSON?
No. Some JavaScript object literals allow trailing commas, but JSON data does not. Remove trailing commas before parsing.
Why does a valid-looking response still fail?
The copied snippet may be incomplete, escaped differently, or wrapped in logs, headers, JSONP, or security prefixes. Paste the raw body into the checker, not a transformed preview.
Related Tool
Related Article
Updated
2026-06-25
Official references
These official references were used to verify the criteria discussed in this article.
- SyntaxError: JSON.parse: bad parsingMDN Web Docs - Checked: 2026-06-25
- Response: json() methodMDN Web Docs - Checked: 2026-06-25