json_decode returns null for both invalid input and valid JSON null — distinguishing failure in PHP 8.1+
Goal Reliably detect whether json_decode() failed due to malformed input versus successfully decoding a JSON document whose top-level value is null . Constraints and uncertainty The function returns PHP null in both cases, so the return value alone cannot signal failure. The standard approach is to call json_last_error() immediately after decoding and compar