json_validateChecks if a string contains valid JSON Description
bool json_validate(string
$json , int $depth = 512, int $flags = 0)
Returns whether the given string is syntactically valid JSON.
If json_validate returns
If json_validate returns json_validate uses less memory than json_decode if the decoded JSON payload is not used, because it does not need to build the array or object structure containing the payload. Caution
Calling json_validate immediately before json_decode will unnecessarily parse the string twice, as json_decode implicitly performs validation during decoding. json_validate should therefore only be used if the decode JSON payload is not immediately used and knowing whether the string contains valid JSON is needed. Parameters
Return Values
Returns Errors/Exceptions
If
If Examples
Example #1 json_validate examples
The above example will output: bool(true) bool(false) See Also
|