get()
Read a single value at a dot or bracket path without fully walking the document in PHP.
Signature
php
JsonFast::get(
string $json,
string $path,
?int $output = OUTPUT_ARRAY
): mixed|nullParameters
| Name | Type | Default | Description |
|---|---|---|---|
$json | string | — | JSON document |
$path | string | — | Dot/bracket path (see syntax below) |
$output | ?int | OUTPUT_ARRAY | Output mode |
Path syntax
| Pattern | Example | Notes |
|---|---|---|
| Dot notation | user.name | Nested object keys |
| Array index | users[0].email | Numeric index in brackets |
| Wildcard | users[*].email | Not supported in get() — use search() |
Returns
The value at $path, or null if the path does not exist.
WARNING
null is ambiguous — it can mean “missing path” or “JSON null at this path”. Use has() when you need to distinguish.
Examples
php
$json = '{"user":{"name":"Allan","profile":{"city":"Milton Keynes"}}}';
JsonFast::get($json, 'user.profile.city'); // "Milton Keynes"
JsonFast::get($json, 'user.name'); // "Allan"
JsonFast::get($json, 'user.missing'); // nullArray index:
php
JsonFast::get('{"items":[{"id":1},{"id":2}]}', 'items[1].id'); // 2String output for a subtree:
php
$subtree = JsonFast::get($json, 'user.profile', JsonFast::OUTPUT_STRING);