HTML Response Instead of JSON – Diagnose API Parse Errors

Local only

If JSON parsing fails at < or <!DOCTYPE, the response may be HTML rather than broken JSON. Inspect the raw HTTP response before editing 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 an endpoint can return HTML when your client expects JSON

A JSON parser only sees the response body, not your expectation. A 404 page, authentication redirect, reverse-proxy error, framework exception page, or CDN challenge can all begin with HTML and trigger a parser error at the first < character. 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. Read the response as text once and inspect its first characters before calling response.json().
  2. Check the HTTP status, Content-Type header, redirect chain, and final request URL.
  3. Fix the endpoint, authentication, proxy, or routing problem that produced HTML, then parse the JSON response.

Common sources of HTML API responses

The HTML is often a useful error document. Its title or body can reveal whether the request hit a 404 route, login screen, application exception handler, load balancer, or CDN layer.

  • Wrong API path or frontend fallback route.
  • Expired authentication redirecting to a login page.
  • Proxy, CDN, or server error page returned before the API handler runs.

Do not repair HTML into JSON

The correct fix is at the HTTP boundary. Removing angle brackets or feeding the HTML to a JSON repair tool would only hide the server-side cause.

HTML returned where JSON was expected

The body is a 404 HTML document. The corrected example shows the kind of JSON payload the client expected after the route is fixed.

Actual response body

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

Expected JSON response

{
  "error": "Not found"
}

Common questions

Frequently asked questions

Why does Unexpected token < often mean HTML?

HTML documents commonly begin with <, while < is not a valid first token for a JSON document.

Should I check Content-Type before parsing JSON?

Yes. Status and Content-Type are useful signals, but also inspect the raw body because misconfigured servers can send incorrect headers.

Can a redirect cause this problem?

Yes. Authentication and routing redirects can lead the client to an HTML page even when the original URL was an API endpoint.

Debugging a specific JSON issue? Browse JSON troubleshooting.