JSON syntax error guide

Unexpected Token < in JSON: What It Means and How to Fix It

A less-than sign at the beginning of a supposed JSON response usually means the body is actually HTML. Common sources are 404 pages, authentication redirects, reverse-proxy errors, framework error screens, or a server route returning markup.

What this JSON error means

Typical parser message
SyntaxError: Unexpected token '<' ... is not valid JSON

Do not start by changing JSON.parse. Inspect the raw HTTP status, Content-Type header, final response URL, and first characters of the response body. Fix the endpoint or server behavior that returned HTML.

Broken JSON vs. corrected JSON

Compare the invalid syntax with a corrected version before applying the same change to your payload.

Invalid JSON

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

Valid JSON

{"error":"not_found","status":404}

Common causes of this JSON error

  • API endpoint returned an HTML 404 page
  • Authentication redirected the request to a login page
  • Reverse proxy or CDN returned an HTML error document
  • Frontend requested the wrong URL
  • Server crashed and returned a framework error page

Fix and validate your JSON

After correcting the suspected syntax, run the complete payload through a validator. If it still fails, use the diagnostic tool to locate the next parser error before formatting the final JSON.

Related JSON errors

JSON error FAQ

What does Unexpected Token < in JSON mean?

A less-than sign at the beginning of a supposed JSON response usually means the body is actually HTML. Common sources are 404 pages, authentication redirects, reverse-proxy errors, framework error screens, or a server route returning markup.

How do I fix Unexpected Token < in JSON?

Do not start by changing JSON.parse. Inspect the raw HTTP status, Content-Type header, final response URL, and first characters of the response body. Fix the endpoint or server behavior that returned HTML.