JSON parse error caused by a UTF-8 BOM or stray output before the body
The response looks like valid JSON but fails to parse because invisible bytes (BOM, whitespace, PHP notices) come first.
Unexpected token in JSON at position 0JSON.parse: unexpected character at line 1 column 1Unexpected token (BOM) JSONUTF-8 BOM breaks JSON parsingSyntaxError: Unexpected token in JSON at position 0 Meaning
A UTF-8 byte-order mark (EF BB BF) or output from a warning/echo/closing ?> before json_encode corrupts the body. Save files as UTF-8 without BOM, remove trailing output and error notices, and check the raw bytes with xxd.
Common causes
- UTF-8 BOM at the start of a PHP/included file
- Warning or notice printed before the JSON
- Whitespace after
?>in an included file display_errorson in production- Compression/proxy adding bytes
⚡ Quick fix
- Save source files as UTF-8 without BOM
- Turn off
display_errors, log instead - Inspect:
curl -s url | xxd | head
Detailed fix by platform
Shell
- bash
curl -s https://example.com/api | head -c 16 | xxd sed -i '1s/^\xEF\xBB\xBF//' file.php
How to diagnose
- First bytes — EF BB BF?
- Notices — Printed?
- Output — Before JSON?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in HTTP
Other ways to find it
Where this error sits
Origin: Network. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026