Supported Versions: PHP 5 >= 5.3.0, PHP 7, PHP 8
Returns the last error occurred
<?php json_last_error(): int
<?php {
$json = json_encode($this->jsonSerialize(), $options);
if (json_last_error() !== JSON_ERROR_NONE) {
throw JsonEncodingException::forModel($this, json_last_error_msg());
}
<?php $json = json_encode(compact('iv', 'value', 'mac', 'tag'), JSON_UNESCAPED_SLASHES);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new EncryptException('Could not encrypt the data.');
}
<?php default => json_encode($data, $this->encodingOptions),
};
if (! $this->hasValidJson(json_last_error())) {
throw new InvalidArgumentException(json_last_error_msg());
}
<?php {
$json = json_encode($this->jsonSerialize(), $options);
if (json_last_error() !== JSON_ERROR_NONE) {
throw JsonEncodingException::forResource($this, json_last_error_msg());
}
<?php $parameters = json_decode(base64_decode(str_replace(['-', '_'], ['+', '/'], $encodedString)), true);
if (json_last_error() !== JSON_ERROR_NONE) {
return null;
}
<?php public function __construct($message = null, $value = null)
{
parent::__construct($message ?: json_last_error());
$this->value = $value;
}
<?php $payload = json_encode($value = $this->createPayloadArray($job, $queue, $data), \JSON_UNESCAPED_UNICODE);
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 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 $parsedValue = json_decode($value, true);
if (json_last_error() === JSON_ERROR_NONE) {
return $parsedValue;
}
<?php $json = json_decode($content);
if (json_last_error() === JSON_ERROR_NONE) {
$content = $json;
}
<?php if ($this->files->exists($full = "{$path}/{$locale}.json")) {
$decoded = json_decode($this->files->get($full), true);
if (is_null($decoded) || json_last_error() !== JSON_ERROR_NONE) {
throw new RuntimeException("Translation file [{$full}] contains an invalid JSON structure.");
}
<?php json_decode($value);
return json_last_error() === JSON_ERROR_NONE;
}