- Can I use peekmo/jsonpath in Laravel 9+ for parsing API responses?
- Yes, but with caveats. The package works in Laravel, but it lacks PHP 8.x support and may conflict with Laravel’s built-in `json_path()` helper (introduced in Laravel 10). For modern Laravel, consider alternatives like `humbug/jsonpath` for RFC 8907 compliance. Wrap usage in a service class to isolate dependencies.
- What PHP versions does peekmo/jsonpath officially support?
- The package supports PHP 5.3–5.6 only, as noted in its documentation. It will likely fail on PHP 7.4+ due to deprecated functions like `create_function()`. For newer PHP, use a polyfill or migrate to a modern alternative like `stevegrunwell/jsonpath`.
- Does peekmo/jsonpath support JSONPath filters (e.g., `?(@.price > 100)`)?
- Yes, it supports basic filters and wildcards (e.g., `$.store..book`), but its implementation is outdated compared to newer libraries. For complex queries like recursive searches (`$..*`) or advanced filters, you may need custom logic or a different package.
- How do I install peekmo/jsonpath in a Laravel project?
- Add it via Composer: `composer require peekmo/jsonpath`. Register it in a service provider or use it directly: `JsonPath::query($json, '$.path.to.field')`. For Laravel, consider publishing a config file if you need reusable settings, though the package itself is dependency-free.
- Is peekmo/jsonpath safe for untrusted JSON input (e.g., API responses)?
- No, this package lacks built-in input validation for JSON injection risks (e.g., malformed paths like `$.store..book[?(@.price > $)]`). Always sanitize JSON with `json_decode($json, true)` or use `JSON_THROW_ON_ERROR` in PHP 7.4+ before passing it to the library.
- Why should I choose peekmo/jsonpath over humbug/jsonpath or stevegrunwell/jsonpath?
- Use this package only if you’re constrained to PHP 5.3–5.6 or need a lightweight drop-in for Stefan Goessner’s original implementation. Alternatives like `humbug/jsonpath` (PHP 8.x, RFC 8907) or `stevegrunwell/jsonpath` (modern features) are actively maintained and support recursive queries, filters, and array slicing.
- Will peekmo/jsonpath break if I upgrade PHP from 5.6 to 7.4+?
- Yes, it will fail due to deprecated functions. Test thoroughly in a staging environment, or replace it with a PHP 7.4+/8.x-compatible alternative. Wrap usage in a service class to isolate the dependency and log deprecation warnings for future migration.
- Can I use peekmo/jsonpath for dynamic field access in Laravel Eloquent models?
- Technically yes, but it’s not recommended for production. The package lacks Laravel-specific optimizations (e.g., query caching, model event hooks). For dynamic access, consider Laravel’s `json_path()` (v10+) or a hybrid approach with `json_decode()` + manual traversal for complex cases.
- Are there any performance issues with deep JSONPath queries in peekmo/jsonpath?
- Yes, deep or complex queries may underperform compared to modern implementations. The package lacks optimizations like recursive descent or array slicing. Benchmark against alternatives like `stevegrunwell/jsonpath` if you’re processing large datasets or nested structures.
- How do I handle edge cases like circular references or non-string JSON keys?
- The package doesn’t explicitly handle circular references and may throw errors on non-string keys. Validate JSON with `json_decode($json, true)` first, and use try-catch blocks for robustness. For circular data, consider flattening the structure or using a custom parser.