peekmo/jsonpath
peekmo/jsonpath adds JSONPath querying to PHP/Laravel, letting you select, filter, and extract values from complex JSON/arrays using familiar JSONPath expressions. Useful for API responses, config inspection, and transforming nested data quickly.
[start:end:step]), recursive descent, or custom functions.$..* for recursive search, filters like ?(@.price > 100)).json_decode() + manual traversal).humbug/jsonpath (PHP 8.x, RFC 8907 compliant).stevegrunwell/jsonpath (modern, feature-rich).$.store..book[?(@.price > $)])?json_path() in Laravel 10+).$.user.*, $.items[0].name).humbug/jsonpath) for feature parity.composer.json:
"require": {
"peekmo/jsonpath": "^1.0"
}
class JsonPathService {
public function query(string $json, string $path): mixed {
return \JsonPath::query($json, $path);
}
}
json_decode with JSON_THROW_ON_ERROR) are used alongside the package.create_function()).nikic/php-parser) for PHP 7+ compatibility.json_path() helper (introduced in v10.0).Peekmo\JsonPath\query()).$.data.id).$.store.book[*].author).json_validate() before querying).create_function() deprecation).JsonPathException).json_decode() + manual traversal).$..* recursive queries).| Failure Type | Impact | Mitigation |
|---|---|---|
| PHP Version Incompatibility | Breaks in PHP 7.4+ | Use a compatibility layer or migrate to alternative. |
| Malformed JSON Input | Silent failures or incorrect results | Validate input with json_validate() (PHP 8.3+) or json_decode() checks. |
| Unsupported JSONPath Syntax | Query failures (e.g., filters) | Document limitations; use fallback logic. |
| Dependency Corruption | Composer install failures | Pin version in composer.lock. |
| Archival Risks | No future updates | Plan for migration to humbug/jsonpath or similar. |
.. vs. *).JsonPathException).$.users[*].name).How can I help you explore Laravel packages today?