Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

Unexpected token ‘<' in JavaScript: How to Find the HTTP Response Behind It

When JSON parsing fails at '

If JavaScript reports Unexpected token '<' while parsing JSON, the input often starts with an HTML page rather than JSON. That can happen when a request reaches a missing endpoint, an error page, or a sign-in page—but the parser message alone does not tell you which. Check the request and response before changing the parser or guessing at the cause.

What the error means

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JSON.parse() expects text that follows JSON grammar. If the first character is <, the input may begin with an HTML tag, which is not valid JSON; parsing it throws a SyntaxError. See MDN’s JSON.parse() reference.

The message identifies a format mismatch: code expected JSON but received something else. It does not, by itself, prove that the server returned a 404 or identify what happened on the server.

As an Amazon Associate I earn from qualifying purchases.

Why Fetch can make the problem easy to miss

A fulfilled fetch() promise means Fetch received a response; it does not mean that the response has a successful HTTP status. A 404 response, for example, does not automatically reject the promise. MDN notes: “The fetch() function will reject the promise on some errors, but not if the server responds with an error status like 404.” Check response.ok or response.status before trying to parse the body. Read more in MDN’s Fetch API guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to diagnose the response

  1. Open the Network panel. Select the failing request and check the requested URL, then note the final URL if the request was redirected.
  2. Check the HTTP status. In Fetch code, branch on response.ok or response.status before calling response.json().
  3. Inspect the content type. Look at the response’s Content-Type header. If the endpoint is supposed to return JSON but the response is labeled HTML, that is a useful clue. MDN documents checking for a JSON content type before consuming a response as JSON in its Fetch API guide.
  4. Read the response body as text. An HTML body may reveal a not-found page, server error, or sign-in page. Use that content together with the status and redirect trail to investigate.
  5. Parse only after confirming the payload. When the response is the expected JSON, use response.json() or parse JSON text with JSON.parse(). Both fail if the body is not valid JSON.

A basic Fetch pattern that checks status and content type before parsing looks like this:

const response = await fetch(url);
if (!response.ok) {
  throw new Error(`HTTP ${response.status}`);
}
const contentType = response.headers.get("content-type");
if (!contentType?.includes("application/json")) {
  throw new TypeError(`Expected JSON, received ${contentType}`);
}
const data = await response.json();

This is an example of the documented checks, not a diagnosis of any particular application. The content-type check is intentionally simple; use the response’s actual headers and your endpoint’s contract when deciding what formats it should accept.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Possible causes to verify

  • Wrong or missing API path: A mistyped route may return an HTML not-found page. Check the request URL and status.
  • Server or gateway failure: An intermediary or server may return an HTML error page. Inspect the response body and status rather than inferring the failure from the parser message.
  • Authentication redirect: A request may be redirected to a sign-in page, whose HTML then reaches the JSON parser. Check the final URL, redirect trail, headers, and body.

These are possibilities to investigate, not causes established by the wording of the error. The evidence is the actual request and response. MDN’s guidance on JavaScript’s “Unexpected token” error explains the syntax-error context; the request details determine what your application received.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.