What is a JSON parse error? (decoder cheatsheet)
Getting Unexpected token or failed to parse JSON? Match the exact error text below, apply the fix, then re-validate your payload.
Common JSON.parse errors decoded
| Error message | Usually means | Quick fix |
|---|---|---|
| Unexpected token < in JSON at position 0 | You parsed HTML (often an error page) instead of JSON. | Inspect response body/status. Verify endpoint and Content-Type before JSON.parse. |
| Unexpected token ' in JSON at position ... | Single quotes were used in keys/strings. | Use double quotes for keys and string values. |
| Unexpected token } / ] in JSON at position ... | Trailing comma or malformed structure. | Remove trailing commas and re-check object/array nesting. |
| Unexpected end of JSON input | Truncated payload or empty response. | Check server output length, buffering, and whether body is empty. |
| Unexpected number in JSON at position ... | Missing comma between fields/array values. | Add commas between adjacent values. |
Copy-ready debug checklist
- Log raw response text before parsing.
- Check HTTP status and Content-Type.
- Validate payload in a JSON formatter.
- Fix structure (quotes, commas, braces) and re-test.
Continue with related guides
Browse the full guides hub or open the JSON formatter tool.