"Unexpected token '<'" in JSON: the server returned HTML
Unexpected token < at position 0 means you received HTML, not JSON. Common causes (404, 500, login pages) and how to debug them.
Error messages you may see
| Chrome · Edge · Node.js | SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON |
|---|---|
| Older Chrome · Node.js 18 and earlier | SyntaxError: Unexpected token < in JSON at position 0 |
| Python json.loads | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) |
| This tool | Line 1, Col 1: Expected a value but found '<' |
Why it happens
The text starts with <, so it is HTML, not JSON. The server most likely returned an error page (404 or 500), a login or redirect page, or your dev server's index.html because the API URL is wrong.
Invalid
<!DOCTYPE html> <html> <head><title>404 Not Found</title></head> </html>
How to fix
Check res.ok and the Content-Type header before calling res.json(), and log await res.text() to see what actually came back. Then fix the URL, the proxy settings or the server error.
Fixed
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(res.headers.get('content-type'));
const data = await res.json();