WP_CLI\Utils
is_json()
Check whether a given string is a valid JSON representation.
Хуков нет.
Возвращает
true|false. Whether the provided string is a valid JSON representation.
Использование
is_json( $argument, $ignore_scalars );
- $argument(строка) (обязательный)
- String to evaluate.
- $ignore_scalars(true|false)
- Whether to ignore scalar values.
По умолчанию:true
Код is_json() is json WP-CLI 2.13.0-alpha
function is_json( $argument, $ignore_scalars = true ) {
if ( ! is_string( $argument ) || '' === $argument ) {
return false;
}
if ( $ignore_scalars && ! in_array( $argument[0], [ '{', '[' ], true ) ) {
return false;
}
json_decode( $argument, $assoc = true );
return json_last_error() === JSON_ERROR_NONE;
}