json_last_error_msg

Supported Versions: PHP 5 >= 5.5.0, PHP 7, PHP 8
Returns the error string of the last json_encode() or json_decode() call
json_last_error_msg(): string
        if ($jsonData === false) {

            throw new 
Exception(sprintf(

                
"The Lambda response cannot be encoded to JSON.\nThis error usually happens when you try to return binary content. If you are writing an HTTP application and you want to return a binary HTTP response (like an image, a PDF, etc.), please read this guide: https://bref.sh/docs/runtimes/http.html#binary-requests-and-responses\nHere is the original JSON error: '%s'",

                
json_last_error_msg()

            ));

        }
        if (! empty($lastLine)) {

            
$result json_decode($lastLinetrue512JSON_THROW_ON_ERROR);

            if (
json_last_error()) {

                throw new 
Exception(json_last_error_msg());

            }

        } else {

            
$result null;
            if ($error !== '') {

                
$result json_decode($errortrue512JSON_THROW_ON_ERROR);

                if (
json_last_error()) {

                    throw new 
Exception(json_last_error_msg());

                }

            }

        }