Skip to content

has()

Check whether a path exists in the document.

Signature

php
JsonFast::has(string $json, string $path): bool

Parameters

NameTypeDescription
$jsonstringJSON document
$pathstringDot/bracket path (same rules as get())

Returns

true if the path exists; false otherwise.

Distinguishes “path missing” from “value is JSON null” — unlike relying on get() alone.

Examples

php
$json = '{"user":{"name":"Allan","optional":null}}';

JsonFast::has($json, 'user.name');      // true
JsonFast::has($json, 'user.optional');  // true (key exists, value is null)
JsonFast::has($json, 'user.missing');   // false

Conditional reads:

php
if (JsonFast::has($config, 'features.beta')) {
    enableBeta(JsonFast::get($config, 'features.beta'));
}

Native tools, weird experiments, and practical performance work.