59 chars · 4 lines
Two-way sync · Edit either side and the other updates automatically.
<!doctype html>59 chars · 4 lines
Two-way sync · Edit either side and the other updates automatically.
<!doctype html>API response troubleshooting
JSON documents cannot begin with HTML markup such as <!doctype html> or <html>. When a fetch call, API client, or framework reports Unexpected token <, inspect the raw response before editing the body because the problem is often routing, authentication, or server error handling rather than JSON syntax. This tool is free to use. No account or payment is required.
Last updated
A wrong route can return a website 404 page, expired authentication can redirect to a login page, and a proxy or platform can substitute its own HTML error document. All of these begin with characters that are invalid JSON.
The right fix is normally at the HTTP or routing layer. Converting or trimming the HTML body only hides the fact that the requested API resource did not return the expected representation.
A fetch request can succeed at the transport layer while still returning an HTML error document that cannot be parsed as JSON.
<!doctype html>
<html><body>404 Not Found</body></html>{
"error": "Not found"
}Common questions
HTML documents commonly begin with <!doctype or an opening tag such as <html, while the less-than character is not valid at the beginning of a JSON value.
No. Inspect the raw response and HTTP status so the application can handle the actual server condition instead of hiding an unexpected response format.
Yes. An expired session can redirect an API request to an HTML sign-in page, which then fails when client code assumes the body is JSON.
Debugging a specific JSON issue? Browse JSON troubleshooting.