json_decode null PHP Origin: Application & API Last updated 13 Oct 2026

json_decode() returns null / JSON_ERROR_SYNTAX: Syntax error

The string passed to json_decode isn’t valid JSON, so PHP returns null.

Exact message you may see json_decode returns nullJsonException: Syntax errorMalformed UTF-8 characters
Seen on: PHP

Meaning

json_decode fails silently unless you check json_last_error() or use JSON_THROW_ON_ERROR. Common inputs that break: BOM at the start, HTML error pages, single quotes, trailing commas, or a body you never read.

Common causes

  • Response is HTML or empty, not JSON
  • UTF-8 BOM / invalid UTF-8
  • Single quotes or trailing commas
  • Reading $_POST instead of php://input

⚡ Quick fix

  1. Use json_decode($s, true, 512, JSON_THROW_ON_ERROR)
  2. Log the raw string when decoding fails
  3. Read raw bodies with file_get_contents('php://input')

Detailed fix by platform

PHP

  1. try { $data = json_decode($raw, true, 512, JSON_THROW_ON_ERROR); } catch (JsonException $e) { error_log($e->getMessage() . ': ' . substr($raw, 0, 200)); }

How to diagnose

  1. Raw — What does the string look like?
  2. Error — json_last_error_msg()

🔧 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: Application & API. Errors that are often confused with or caused by this one (click to open):

circular JSON — TypeError: Converting circular structure to JSON (JavaScript)circular JSONentity.parse.failed — API Error: Malformed JSON in request body (entity.parse.failed / JSON parse error) (API)entity.parse.failedHttpMessageNotReadableException — HttpMessageNotReadableException: JSON parse error / Required request body is missing (Java)HttpMessageNotReadabl…InvalidDefinitionException — com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class X and no properties discovered (Java)InvalidDefinitionExce…is an invalid start of a value — System.Text.Json: '<' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0 (.NET)is an invalid start o…MismatchedInputException — com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.util.ArrayList` from Object value (Java)MismatchedInputExcept…SyntaxError: JSON — SyntaxError: Unexpected token < in JSON at position 0 (JavaScript)SyntaxError: JSONThe JSON value could not be converted — System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $.id (.NET)The JSON value could …json_deco…

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.