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
<?php json_last_error_msg(): string
<?php         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()

            ));

        }
<?php         if (! empty($lastLine)) {

            $result = json_decode($lastLine, true, 512, JSON_THROW_ON_ERROR);

            if (json_last_error()) {

                throw new Exception(json_last_error_msg());

            }

        } else {

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

                $result = json_decode($error, true, 512, JSON_THROW_ON_ERROR);

                if (json_last_error()) {

                    throw new Exception(json_last_error_msg());

                }

            }

        }