ERROR - Updated 2026-05-15

Unexpected token < in JSON at position 0

Why Unexpected token < in JSON at position 0 usually means your API returned HTML, not JSON, and how to debug it.

Open JSON Error Doctor

Quick Answer

Unexpected token < in JSON at position 0 usually means the response starts with <, so the parser is seeing HTML instead of JSON. Common causes include a 404 page, a login page, a server error page, or a development proxy returning the front-end app. Debug the HTTP response before changing JSON syntax.

Why This Matters

This error is one of the most common API debugging traps. The JSON parser is not telling you that < belongs in your JSON. It is telling you that the first character of the response is not JSON at all.

Common Causes

Response Starts WithLikely CauseCheck
<!doctype html>HTML page returnedRequest URL
<html> login pageAuth expiredCookies, token, redirect
404 HTMLMissing routeAPI path and base URL
500 HTMLServer error pageServer logs
Front-end app HTMLProxy fallbackDev server or rewrite config

Practical Workflow

  1. Open the failed request in the browser Network tab.
  2. Check status code and Request URL.
  3. Check the Content-Type header.
  4. Copy the response body and inspect the first 200 characters.
  5. Use JSON Error Doctor only after confirming the body is meant to be JSON.

Example

const response = await fetch("/api/profile");
const text = await response.text();
console.log(response.status, response.headers.get("content-type"), text.slice(0, 200));

If text starts with HTML, fix routing, authentication, or server error handling. Do not try to "repair" the HTML as JSON.

Common Mistakes

  • Calling response.json() without checking status code.
  • Missing a base URL difference between local and production.
  • Treating a login redirect as a successful API response.
  • Assuming HTTP 200 always means JSON.

Related Tool

Related Article

Updated

2026-05-15