json_last_error

PHP 5 >= 5.3.0, PHP 7, PHP 8
json_last_error - Returns the last error occurred
Manual
Code Examples

Example #1 json_last_error example

Result: Decoding: {"Organization": "PHP Documentation Team"} - No errors Decoding: {'Organization': 'PHP Documentation Team'} - Syntax error, malformed JSON
PHP Version:

Example #2 json_last_error with json_encode

Result: string(4) "null" bool(true)
PHP Version:

Example #3 json_last_error and <span class='function-constant'>JSON_THROW_ON_ERROR</span>

Result: bool(true)
PHP Version:


Function json_last_error:

JavaScript Object Notation Functions

Most used PHP functions