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 ($value === false) {

            throw JsonEncodingException::forAttribute(

                $this, $key, json_last_error_msg()

            );

        }
<?php         $json = json_encode($this->jsonSerialize(), $options);



        if (json_last_error() !== JSON_ERROR_NONE) {

            throw JsonEncodingException::forModel($this, json_last_error_msg());

        }



        return $json;
<?php         };



        if (! $this->hasValidJson(json_last_error())) {

            throw new InvalidArgumentException(json_last_error_msg());

        }



        return $this->update();
<?php         $json = json_encode($this->jsonSerialize(), $options);



        if (json_last_error() !== JSON_ERROR_NONE) {

            throw JsonEncodingException::forResource($this, json_last_error_msg());

        }



        return $json;
<?php             $content = $this->morphToJson($content);



            if ($content === false) {

                throw new InvalidArgumentException(json_last_error_msg());

            }

        }
<?php         if (json_last_error() !== JSON_ERROR_NONE) {

            throw new InvalidPayloadException(

                'Unable to JSON encode payload. Error ('.json_last_error().'): '.json_last_error_msg(), $value

            );

        }
<?php         $encoded = json_encode($value);



        if (json_last_error() !== JSON_ERROR_NONE) {

            throw ConversionException::conversionFailedSerialization($value, 'json', json_last_error_msg());

        }



        return $encoded;
<?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());

                }

            }

        }