Quick Answer
json_decode() returns null on invalid JSON. Check json_last_error() to get the error code and json_last_error_msg() for a human-readable message. Common errors: syntax error (malformed JSON), unexpected control character, recursion depth exceeded. In PHP 7.3+ you can pass JSON_THROW_ON_ERROR flag to have it throw a JsonException instead of returning null silently.
Answer
json_decode() returns null on failure and json_last_error() provides the error code. Proper handling is required when interacting with APIs.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.
PHP interview questions and answers for beginner, junior, mid-level, senior, and expert developers. Ideal for freshers and experienced candidates preparing for PHP roles.