Fast Diagnosis Checklist
- Inspect raw response body before calling
JSON.parseorresponse.json(). - Confirm content-type is
application/json. - Run payload through JSON Validator.
- Reformat payload in JSON Formatter to locate breakpoints.
Typical Root Causes
- Server returned HTML error page (token
<at position 0). - Trailing commas or missing quotes in JSON body.
- Double-encoded escaped JSON string not decoded first.
- Unexpected BOM or invisible characters at payload start.
Minimal Repro Example
const raw = "<html>Not JSON</html>";
JSON.parse(raw); // Unexpected token < in JSON at position 0Fix Workflow
- Log the raw response string (do not parse yet).
- Validate in JSON Validator.
- If it is JSON but escaped, decode with String to JSON.
- Compare expected vs actual payloads using JSON Diff.
Language Snippets
JavaScript
const text = await response.text();
console.log(text.slice(0, 200));
const data = JSON.parse(text);Python
import json
raw = response.text
json.loads(raw)FAQ
Why does this happen only in production?
Production responses often include error pages, CDNs, or auth redirects that do not exist in staging.
Should I auto-retry parsing?
No. Inspect the raw response first. Retrying without fixing the source usually hides the real issue.