json_validate

FunctionAdded in PHP 8.3

Checks if a string contains valid JSON.

PHP 5
PHP 7
PHP 8.0
PHP 8.1
PHP 8.2
PHP 8.3
Added
PHP 8.4
PHP 8.5

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

PHP VersionAvailability
PHP 8.5Future Release Yes
PHP 8.4Upcoming Release Yes
PHP 8.3Supported (Latest) Yes
PHP 8.2Supported 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