Unexpected Token < in JSON – Why It Happens

Local only

A less-than sign at the start of a supposed JSON response usually means the body is HTML, not JSON. Check the raw response, status code, content type, redirects, and endpoint before trying to repair the payload.

Indent

59 chars · 4 lines

Two-way sync · Edit either side and the other updates automatically.

Invalid JSONExpected a JSON value
Line 1Column 1Character 1Found “<”
<!doctype html>

API response troubleshooting

Why a JSON parser sees the < character

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

What you can do here

  • Browser-local JSON processing
  • Route-specific malformed JSON example
  • Focused parser or repair guidance
  • Broken and corrected JSON example
  • Related JSON problem navigation

Steps

  1. Inspect the raw response text before calling JSON.parse or response.json().
  2. Check HTTP status, Content-Type, redirects, and the final request URL.
  3. Fix the endpoint or server response so it returns JSON, then parse again.

Common reasons an API returns HTML instead of JSON

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.

  • 404 or 500 HTML error pages.
  • Login or single-sign-on redirects.
  • Frontend index.html returned for an API route.
  • Proxy, CDN, or platform error pages.

Do not repair HTML into 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.

HTML returned where JSON was expected

A fetch request can succeed at the transport layer while still returning an HTML error document that cannot be parsed as JSON.

Actual response body

<!doctype html>
<html><body>404 Not Found</body></html>

Expected JSON body

{
  "error": "Not found"
}

Common questions

Frequently asked questions

Why does Unexpected token < usually mean HTML?

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.

Should I catch the error and ignore it?

No. Inspect the raw response and HTTP status so the application can handle the actual server condition instead of hiding an unexpected response format.

Can a login redirect cause this error?

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.