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.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

JSON.parse() throws a SyntaxError when its input is not valid JSON. If the error points to <, the input may start with HTML—often because code expected JSON but received a web page instead. The error alone does not reveal why. Check the raw response, HTTP status, and Content-Type before choosing a fix.

What “Unexpected token <” means

The parser encountered a character that cannot begin valid JSON at the position it reports. A less-than sign often appears at the start of HTML, such as an error page, but the message is a clue about the input—not a diagnosis of the server or endpoint. Confirm by inspecting the body that your code actually tried to parse.

This can happen with JSON.parse(text) or with response.json(), which reads a response body and parses it as JSON. If the body contains HTML or other non-JSON text, parsing fails.

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

How to diagnose the response

  1. Find the parsing call. Locate the code path using JSON.parse() or response.json(), and identify the exact string or response body being passed to it.
  2. Check the HTTP status. With fetch(), inspect response.status or response.ok. A 404 response does not by itself cause the fetch promise to reject, so code may continue and try to parse an error page. See MDN’s Fetch guide.
  3. Check the response content type. Read the Content-Type header and compare it with what the endpoint is supposed to return. MDN shows checking this header before reading a response as JSON: Using Fetch.
  4. Inspect the body as text if the response is unexpected. For diagnosis, read the body as text and examine what it contains rather than immediately parsing it as JSON. MDN documents the response body readers, including text and JSON: Fetch response handling.
  5. Compare the body with the API contract. If it is HTML, investigate the requested URL, server route, authentication or error handling, and redirects as possibilities. The parser error alone cannot tell you which one occurred.

How to read other JSON.parse errors

JavaScript engines phrase syntax errors differently. Treat the reported token and position as a pointer to inspect the input; do not infer the exact cause from one character alone.

  • “Unexpected token o” or another letter: the parser found input inconsistent with JSON at that point. Inspect the full text and reported location.
  • “Unexpected end of JSON input” or “unexpected end of data”: the input ended before a complete JSON value was available.
  • Unexpected character after JSON data: extra non-whitespace text may follow an otherwise complete JSON value.
  • Trailing comma or single-quoted property name: JSON syntax is not the same as JavaScript object-literal syntax. JSON requires double-quoted property names and does not allow trailing commas. See MDN’s JSON.parse reference.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fix the underlying mismatch

Choose the fix based on what the response contains. If the request reached the wrong route or received an HTML page, correct the URL, routing, or response handling so the client gets the intended API response. If the server returned an error status, handle that status before trying to parse a success payload. If the body is meant to be JSON, correct the invalid syntax at the reported location. Do not try to make HTML parse as JSON or suppress the exception without addressing the unexpected input.

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.