ERROR - Updated 2026-05-15
Unexpected token < in JSON at position 0
Why Unexpected token < in JSON at position 0 usually means your API returned HTML, not JSON, and how to debug it.
Open JSON Error DoctorQuick Answer
Unexpected token < in JSON at position 0 usually means the response starts with <, so the parser is seeing HTML instead of JSON. Common causes include a 404 page, a login page, a server error page, or a development proxy returning the front-end app. Debug the HTTP response before changing JSON syntax.
Why This Matters
This error is one of the most common API debugging traps. The JSON parser is not telling you that < belongs in your JSON. It is telling you that the first character of the response is not JSON at all.
Common Causes
| Response Starts With | Likely Cause | Check |
|---|---|---|
<!doctype html> | HTML page returned | Request URL |
<html> login page | Auth expired | Cookies, token, redirect |
| 404 HTML | Missing route | API path and base URL |
| 500 HTML | Server error page | Server logs |
| Front-end app HTML | Proxy fallback | Dev server or rewrite config |
Practical Workflow
- Open the failed request in the browser Network tab.
- Check status code and Request URL.
- Check the
Content-Typeheader. - Copy the response body and inspect the first 200 characters.
- Use JSON Error Doctor only after confirming the body is meant to be JSON.
Example
const response = await fetch("/api/profile");
const text = await response.text();
console.log(response.status, response.headers.get("content-type"), text.slice(0, 200));
If text starts with HTML, fix routing, authentication, or server error handling. Do not try to "repair" the HTML as JSON.
Common Mistakes
- Calling
response.json()without checking status code. - Missing a base URL difference between local and production.
- Treating a login redirect as a successful API response.
- Assuming HTTP 200 always means JSON.
Related Tool
Related Article
Updated
2026-05-15