JavaScript & Node Error

Fix "SyntaxError: Unexpected token < in JSON at position 0"

Developer guide and instant terminal command to diagnose and solve this error.

Terminal Output
$SyntaxError: Unexpected token < in JSON at position 0

Why Does This Error Happen?

Your client-side code called response.json(), but the backend API server returned an HTML error page (like a 404, 500, or Nginx error page starting with "<!DOCTYPE html>").

Instant Terminal One-Liner Fixes

Linux (Bash / Zsh)
curl -i https://api.yourdomain.com/endpoint
macOS (Terminal / iTerm2)
curl -i https://api.yourdomain.com/endpoint
Windows (PowerShell Run as Administrator)
curl.exe -i https://api.yourdomain.com/endpoint

Comprehensive Step-by-Step Resolution

  1. 1Check the HTTP response status code before parsing ("if (!res.ok) throw new Error(...)").
  2. 2Inspect the raw text using "await res.text()" to see the actual HTML server error message.
  3. 3Ensure the API endpoint URL path is correct and backend server is running.
Dedicated Companion Tool

Troubleshoot using the JSON Validator & Formatter

Use our client-side utility with zero server upload for instant debugging.

Open Tool

Frequently Asked Questions

Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

Your client-side code called response.json(), but the backend API server returned an HTML error page (like a 404, 500, or Nginx error page starting with "<!DOCTYPE html>").