json_validate
Function • Added in PHP 8.3
Checks if a string contains valid JSON.
json_validate Function synopsis
json_validate(
string $json,
int $depth = 512,
int $flags = 0
): bool
Parameters
$json
Typestring
The string to validate.
$depth
OptionalTypeintDefault value512
Maximum nesting depth of the structure being decoded.
The value must be greater than 0,
and less than or equal to 2147483647.
$flags
OptionalTypeintDefault value0
Currently only
JSON_INVALID_UTF8_IGNORE
is accepted.
$flags accepts the following constant value
Return value
Typebool
Returns true if the given string is syntactically valid JSON, otherwise
returns false.
Changes to the json_validate Function
PHP 8.3
- Function added
json_validate Function Availability
json_validate Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Future Release | Yes |
| PHP 8.5Upcoming Release | Yes |
| PHP 8.4Supported (Latest) | Yes |
| PHP 8.3Supported | Yes |
| PHP 8.2Security-Fixes Only | No |
| PHP 8.1Security-Fixes Only | No |
| PHP 8.0Unsupported | No |
| PHP 7.4Unsupported | No |
| PHP 7.3Unsupported | No |
| PHP 7.2Unsupported | No |
| PHP 7.1Unsupported | No |
| PHP 7.0Unsupported | No |
| PHP 5.6Unsupported | No |
| PHP 5.5Unsupported | No |
| PHP 5.4Unsupported | No |
| PHP 5.3Unsupported | No |