ergebnis/json-pointer
RFC 6901 JSON Pointer abstraction for PHP. Create and convert reference tokens and pointers from plain strings, JSON string form, or URI fragment identifiers, with correct escaping and encoding. Install via Composer and use small, typed value objects.
Illuminate\Support\Json, Laravel\Sanctum, Spatie\ArrayToXml) could benefit from standardized pointer-based navigation, reducing ad-hoc string parsing (e.g., data->{"user.profile"} → Pointer::from("/user/profile")).require ergebnis/json-pointer).ReferenceToken, Pointer), reducing runtime errors.Pointer::from()->get()), which aligns with Laravel’s service container and dependency injection.Json::decode() would need pre-validation.JsonException; Laravel’s json_decode() with JSON_THROW_ON_ERROR mitigates this.explode('.', $path)) with Pointer::from("/user/profile").if (Pointer::from("/data/required_field")->exists($payload))).Illuminate\Support\Collection with a pointer() method for fluent traversal./~0 vs /~).JsonPointer (more mature but heavier).composer require ergebnis/json-pointer).app()->bind(Pointer::class)) for dependency injection.ReferenceToken and Pointer improve static analysis.Pointer::from().// Before
$value = data_get($array, 'user.profile.name');
// After
$pointer = Pointer::from('/user/profile/name');
$value = $pointer->get($array);
JsonPointer::resolve($path, $data)) for consistency.pointer() method:
$collection->pointer('/key/subkey')->get();
RequiredPointer for API payloads).declare(strict_types=0) but loses type safety.| Step | Priority | Effort | Dependencies |
|---|---|---|---|
| Install package | High | Low | Composer |
| Unit tests | High | Medium | PHPUnit/Pest |
| Facade wrapper | Medium | Low | Laravel core |
| Collection macro | Low | Medium | Laravel Collections |
| API validation | High | High | Laravel Validation |
Pointer::validate($path)).| Scenario | Impact | Mitigation |
|---|---|---|
| Invalid pointer syntax | JsonException |
Validate with Pointer::from()->isValid() |
| Non-JSON data | TypeError |
Pre-process with json_decode() |
| Circular references | Infinite loop | Use Json::decode() with JSON_BIGINT_AS_STRING |
| Large JSON payloads | Memory usage | Stream processing (Laravel’s JsonStream) |
Pointer::from() syntax and RFC 6901 basics.ReferenceToken methods.How can I help you explore Laravel packages today?