extract()
Read multiple paths in one call and return a flat map.
Signature
php
JsonFast::extract(
string $json,
array $paths,
?int $output = OUTPUT_ARRAY
): mixedParameters
| Name | Type | Default | Description |
|---|---|---|---|
$json | string | — | JSON document |
$paths | array | — | List of path strings |
$output | ?int | OUTPUT_ARRAY | Output mode |
Returns
Associative map keyed by path string. Missing paths map to null.
Examples
php
$json = '{"user":{"name":"Allan","email":"allan@example.com"}}';
$result = JsonFast::extract($json, [
'user.name',
'user.email',
'user.phone',
]);
/*
[
'user.name' => 'Allan',
'user.email' => 'allan@example.com',
'user.phone' => null,
]
*/Projection for APIs:
php
$view = JsonFast::extract($document, [
'meta.version',
'meta.updated',
'data.summary',
]);String output for each extracted subtree:
php
$parts = JsonFast::extract($json, ['config', 'secrets'], JsonFast::OUTPUT_STRING);vs multiple get() calls
One native pass over the document — useful when you need several fields from a large payload and want to avoid repeated full decodes in PHP.
