json_last_error

Supported Versions: PHP 5 >= 5.3.0, PHP 7, PHP 8
Returns the last error occurred
json_last_error(): int
        $lastLine end($output);

        if (! empty(
$lastLine)) {

            
$result json_decode($lastLinetrue512JSON_THROW_ON_ERROR);

            if (
json_last_error()) {

                throw new 
Exception(json_last_error_msg());

            }

        } else {
            $error trim($matches[1] ?? '');

            if (
$error !== '') {

                
$result json_decode($errortrue512JSON_THROW_ON_ERROR);

                if (
json_last_error()) {

                    throw new 
Exception(json_last_error_msg());

                }

            }