symfony/json-path
Symfony JsonPath is a PHP component for navigating and querying JSON using JSONPath syntax per RFC 9535. Use JsonCrawler to evaluate paths, filter expressions, and extract values from complex JSON documents.
The JsonPath component eases JSON navigation using the JSONPath syntax as described in RFC 9535.
composer require symfony/json-path
use Symfony\Component\JsonPath\JsonCrawler;
$json = <<<'JSON'
{"store": {"book": [
{"category": "reference", "author": "Nigel Rees", "title": "Sayings", "price": 8.95},
{"category": "fiction", "author": "Evelyn Waugh", "title": "Sword", "price": 12.99}
]}}
JSON;
$crawler = new JsonCrawler($json);
$result = $crawler->find('$.store.book[0].title');
$result = $crawler->find('$.store.book[?match(@.author, "[A-Z].*el.+")]');
$result = $crawler->find("$.store.book[?(@.category == 'fiction')].title");
The compliance test suite is gathered from the JSONPath Test Suite.
When new commits are pushed to the upstream repository, it is necessary to gather them by following these steps:
reference field of composer.json to the latest commit hash of the jsonpath-standard/jsonpath-compliance-test-suite packageversion field to the date of the commitcomposer.json file present at the root level of the symfony/symfony repositorycomposer updateThis package is looking for a backer.
Help Symfony by sponsoring its development!
How can I help you explore Laravel packages today?