PlainError

Uncaught SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON

Last checked 2026-10-26 · 3 fixes · reviewed answer

TL;DRJavaScript tried to read a server response as JSON data but instead received an HTML page (starting with <!DOCTYPE), which is invalid for JSON parsing.

Most likely cause: API or fetch call received an HTML error page, login redirect, or 404 instead of expected JSON

Try first: Open browser developer tools and check the Network tab

Likely causes

  1. API or fetch call received an HTML error page, login redirect, or 404 instead of expected JSONmost likely
  2. Incorrect endpoint URL or missing headers causing the server to return HTMLpossible
  3. CORS, proxy, or network issue returning a default error HTML documentless likely

How to fix it

Safest first: SafeChanges settingsDangerous
  1. Open browser developer tools and check the Network tabSafe

    Reload the page, find the failing request, and view the Response tab to see the actual HTML content returned.

  2. Verify the request URL and headers in your codeSafe

    Ensure the fetch or AJAX call targets the correct JSON-producing endpoint and includes any required Accept: application/json header.

  3. Add error handling around the JSON parseSafe

    Wrap the response.json() call in a try/catch or check response.ok before parsing to log the actual body on failure.

If that didn't fix it

Log the full response text (not just JSON) from the failing request and examine server logs for the endpoint.

When to see a technician

Contact the backend developer or site administrator when the error occurs on a live service you do not control.

Quick answers

What does Uncaught SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON mean?
JavaScript tried to read a server response as JSON data but instead received an HTML page (starting with <!DOCTYPE), which is invalid for JSON parsing.
What causes Uncaught SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON?
API or fetch call received an HTML error page, login redirect, or 404 instead of expected JSON. (most likely) Incorrect endpoint URL or missing headers causing the server to return HTML. (possible) CORS, proxy, or network issue returning a default error HTML document. (less likely)
How do I fix Uncaught SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON?
Try these in order, safest first: 1. Open browser developer tools and check the Network tab. 2. Verify the request URL and headers in your code. 3. Add error handling around the JSON parse.
What if that didn't fix it?
Log the full response text (not just JSON) from the failing request and examine server logs for the endpoint.
When should I see a technician?
Contact the backend developer or site administrator when the error occurs on a live service you do not control.
Did this fix it? Report a problem

Related errors

All Coding errors →