BOM HTTP Origin: Network OSI layer 6 · Presentation Last updated 18 Nov 2026

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.

Exact message you may see 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
Seen on: HTTP PHP JavaScript

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_errors on in production
  • Compression/proxy adding bytes

⚡ Quick fix

  1. Save source files as UTF-8 without BOM
  2. Turn off display_errors, log instead
  3. Inspect: curl -s url | xxd | head

Detailed fix by platform

Shell

  1. bash
    curl -s https://example.com/api | head -c 16 | xxd
    sed -i '1s/^\xEF\xBB\xBF//' file.php

How to diagnose

  1. First bytes — EF BB BF?
  2. Notices — Printed?
  3. 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:

Where this error sits

Origin: Network. Errors that are often confused with or caused by this one (click to open):

102 — HTTP 102 Processing (HTTP)102201 — HTTP 201 Created (HTTP)201202 — HTTP 202 Accepted (HTTP)202203 — HTTP 203 Non-Authoritative Information (HTTP)203400 — HTTP 400 Bad Request (HTTP)400json_decode null — json_decode() returns null / JSON_ERROR_SYNTAX: Syntax error (PHP)json_decode nullJSONDecodeError — json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) (Python)JSONDecodeErrorreq.body undefined — Express: req.body is undefined / {} (body parser missing) (Node.js)req.body undefinedBOM

Explore the map of this error Full error map →

🧠 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.