json_last_error

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

        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 {
<?php             $error = trim($matches[1] ?? '');

            if ($error !== '') {

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

                if (json_last_error()) {

                    throw new Exception(json_last_error_msg());

                }

            }