{"id":15293359,"url":"https://github.com/ergebnis/json-pointer","last_synced_at":"2025-04-12T02:14:10.503Z","repository":{"id":37855535,"uuid":"453098794","full_name":"ergebnis/json-pointer","owner":"ergebnis","description":"📃 Provides a composer package with an abstraction of a JSON pointer.","archived":false,"fork":false,"pushed_at":"2025-03-24T16:19:29.000Z","size":1959,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T02:14:03.586Z","etag":null,"topics":["json","pointer"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ergebnis.png","metadata":{"funding":{"github":["ergebnis","localheinz"]},"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-28T14:31:35.000Z","updated_at":"2025-03-24T16:19:31.000Z","dependencies_parsed_at":"2023-09-21T19:01:42.672Z","dependency_job_id":"37f99d6c-1f78-402b-a9c1-c912def3a01b","html_url":"https://github.com/ergebnis/json-pointer","commit_stats":{"total_commits":205,"total_committers":3,"mean_commits":68.33333333333333,"dds":"0.35609756097560974","last_synced_commit":"3d43d629914561d287d83fadc24f9b5e5c0149d5"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":"ergebnis/php-package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergebnis%2Fjson-pointer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergebnis%2Fjson-pointer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergebnis%2Fjson-pointer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergebnis%2Fjson-pointer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ergebnis","download_url":"https://codeload.github.com/ergebnis/json-pointer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505925,"owners_count":21115354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json","pointer"],"created_at":"2024-09-30T16:47:09.600Z","updated_at":"2025-04-12T02:14:10.481Z","avatar_url":"https://github.com/ergebnis.png","language":"PHP","funding_links":["https://github.com/sponsors/ergebnis","https://github.com/sponsors/localheinz"],"categories":[],"sub_categories":[],"readme":"# json-pointer\n\n[![Integrate](https://github.com/ergebnis/json-pointer/workflows/Integrate/badge.svg)](https://github.com/ergebnis/json-pointer/actions)\n[![Merge](https://github.com/ergebnis/json-pointer/workflows/Merge/badge.svg)](https://github.com/ergebnis/json-pointer/actions)\n[![Release](https://github.com/ergebnis/json-pointer/workflows/Release/badge.svg)](https://github.com/ergebnis/json-pointer/actions)\n[![Renew](https://github.com/ergebnis/json-pointer/workflows/Renew/badge.svg)](https://github.com/ergebnis/json-pointer/actions)\n\n[![Code Coverage](https://codecov.io/gh/ergebnis/json-pointer/branch/main/graph/badge.svg)](https://codecov.io/gh/ergebnis/json-pointer)\n\n[![Latest Stable Version](https://poser.pugx.org/ergebnis/json-pointer/v/stable)](https://packagist.org/packages/ergebnis/json-pointer)\n[![Total Downloads](https://poser.pugx.org/ergebnis/json-pointer/downloads)](https://packagist.org/packages/ergebnis/json-pointer)\n[![Monthly Downloads](http://poser.pugx.org/ergebnis/json-pointer/d/monthly)](https://packagist.org/packages/ergebnis/json-pointer)\n\nThis project provides a [`composer`](https://getcomposer.org) package with an abstraction of a [JSON pointer](https://datatracker.ietf.org/doc/html/rfc6901).\n\n## Installation\n\nRun\n\n```sh\ncomposer require ergebnis/json-pointer\n```\n\n## Usage\n\n### `ReferenceToken`\n\nYou can create a `ReferenceToken` from a `string` value:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$referenceToken = Pointer\\ReferenceToken::fromString('foo/9000/😆');\n\n$referenceToken-\u003etoJsonString();                  // 'foo~19000~😆'\n$referenceToken-\u003etoString();                      // 'foo/9000/😆'\n$referenceToken-\u003etoUriFragmentIdentifierString(); // 'foo~19000~1%F0%9F%98%86'\n```\n\nYou can create a `ReferenceToken` from a [JSON `string` value](https://datatracker.ietf.org/doc/html/rfc6901#section-5):\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$referenceToken = Pointer\\ReferenceToken::fromJsonString('foo~19000~😆');\n\n$referenceToken-\u003etoJsonString();                  // 'foo~19000~😆'\n$referenceToken-\u003etoString();                      // 'foo/9000/😆'\n$referenceToken-\u003etoUriFragmentIdentifierString(); // 'foo~19000~1%F0%9F%98%86'\n```\n\nYou can create a `ReferenceToken` from a [URI fragment identifier `string` value](https://datatracker.ietf.org/doc/html/rfc6901#section-6):\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$referenceToken = Pointer\\ReferenceToken::fromUriFragmentIdentifierString('foo~19000~1%F0%9F%98%86');\n\n$referenceToken-\u003etoJsonString();                  // 'foo~19000~😆'\n$referenceToken-\u003etoString();                      // 'foo/9000/😆'\n$referenceToken-\u003etoUriFragmentIdentifierString(); // 'foo~19000~1%F0%9F%98%86'\n```\n\nYou can create a `ReferenceToken` from an `int` value:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$referenceToken = Pointer\\ReferenceToken::fromInt(9001);\n\n$referenceToken-\u003etoJsonString();                  // '9001'\n$referenceToken-\u003etoString();                      // '9001'\n$referenceToken-\u003etoUriFragmentIdentifierString(); // '9001'\n```\n\nYou can compare `ReferenceToken`s:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$one = Pointer\\ReferenceToken::fromString('foo/bar');\n$two = Pointer\\ReferenceToken::fromJsonString('foo~1bar');\n$three = Pointer\\ReferenceToken::fromString('foo/9000');\n\n$one-\u003eequals($two);   // true\n$one-\u003eequals($three); // false\n```\n\n### `JsonPointer`\n\nYou can create a `JsonPointer` referencing a document:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$jsonPointer = Pointer\\JsonPointer::document();\n\n$jsonPointer-\u003etoJsonString();                  // ''\n$jsonPointer-\u003etoUriFragmentIdentifierString(); // '#'\n```\n\nYou can create a `JsonPointer` from a [JSON `string` representation](https://datatracker.ietf.org/doc/html/rfc6901#section-5) value:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$jsonPointer = Pointer\\JsonPointer::fromJsonString('/foo/bar/😆');\n\n$jsonPointer-\u003etoJsonString();                  // '/foo/bar/😆'\n$jsonPointer-\u003etoUriFragmentIdentifierString(); // '#/foo/bar/%F0%9F%98%86'\n```\n\nYou can create a `JsonPointer` from a [URI fragment identifier `string` representation](https://datatracker.ietf.org/doc/html/rfc6901#section-6) value:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$jsonPointer = Pointer\\JsonPointer::fromUriFragmentIdentifierString('#/foo/bar/%F0%9F%98%86');\n\n$jsonPointer-\u003etoJsonString();                  // '/foo/bar/😆'\n$jsonPointer-\u003etoUriFragmentIdentifierString(); // '#/foo/bar/%F0%9F%98%86'\n```\n\nYou can create a `JsonPointer` from `ReferenceToken`s:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$referenceTokens = [\n    Pointer\\ReferenceToken::fromString('foo'),\n    Pointer\\ReferenceToken::fromString('bar'),\n];\n\n$jsonPointer = Pointer\\JsonPointer::fromReferenceTokens(...$referenceTokens);\n\n$jsonPointer-\u003etoJsonString();                  // '/foo/bar'\n$jsonPointer-\u003etoUriFragmentIdentifierString(); // '#/foo/bar'\n```\n\nYou can compare `JsonPointer`s:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$one = Pointer\\JsonPointer::fromJsonString('/foo/bar');\n$two = Pointer\\JsonPointer::fromJsonString('/foo~1bar');\n$three = Pointer\\JsonPointer::fromUriFragmentIdentifierString('#/foo/bar');\n\n$one-\u003eequals($two);   // false\n$one-\u003eequals($three); // true\n```\n\nYou can append a `ReferenceToken` to a `JsonPointer`:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$jsonPointer = Pointer\\JsonPointer::fromJsonString('/foo/bar');\n\n$referenceToken = Pointer\\ReferenceToken::fromString('baz');\n\n$newJsonPointer = $jsonPointer-\u003eappend($referenceToken);\n\n$newJsonPointer-\u003etoJsonString();                  // '/foo/bar/baz'\n$newJsonPointer-\u003etoUriFragmentIdentifierString(); // '#foo/bar/baz'\n```\n\n### `Specification`\n\nYou can create a `Specification` that is always satisfied by a `JsonPointer`:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$specification = Pointer\\Specification::always();\n\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo'));     // true\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo/bar')); // true\n```\n\nYou can create a `Specification` that is satisfied when a closure returns `true` for a `JsonPointer`:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$specification = Pointer\\Specification::closure(static function (Pointer\\JsonPointer $jsonPointer) {\n    return $jsonPointer-\u003etoJsonString() === '/foo/bar';\n});\n\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo'));     // false\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo/bar')); // true\n```\n\nYou can create a `Specification` that is satisfied when a `JsonPointer` equals another `JsonPointer`:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$specification = Pointer\\Specification::equals(Pointer\\JsonPointer::fromJsonString('/foo/bar'));\n\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo'));     // false\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo/bar')); // true\n```\n\nYou can create a `Specification` that is never satisfied by a `JsonPointer`:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$specification = Pointer\\Specification::never();\n\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo'));     // false\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo/bar')); // false\n```\n\nYou can create a `Specification` that is satisfied when another `Specification` is not satisfied by a `JsonPointer`:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$specification = Pointer\\Specification::not(Pointer\\Specification::equals(Pointer\\JsonPointer::fromJsonString('/foo/bar')));\n\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo'));     // true\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo/bar')); // false\n```\n\nYou can compose `Specification`s to find out if a `JsonPointer` satisfies any of them:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\Json\\Pointer;\n\n$specification = Pointer\\Specification::anyOf(\n    Pointer\\Specification::closure(static function(Pointer\\JsonPointer $jsonPointer) {\n        return $jsonPointer-\u003etoJsonString() === '/foo/bar';\n    }),\n    Pointer\\Specification::equals(Pointer\\JsonPointer::fromJsonString('/foo/baz')),\n    Pointer\\Specification::never(),\n);\n\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo'));     // false\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo/bar')); // true\n$specification-\u003eisSatisfiedBy(Pointer\\JsonPointer::fromJsonString('/foo/baz')); // true\n```\n\n## Changelog\n\nThe maintainers of this project record notable changes to this project in a [changelog](CHANGELOG.md).\n\n## Contributing\n\nThe maintainers of this project suggest following the [contribution guide](.github/CONTRIBUTING.md).\n\n## Code of Conduct\n\nThe maintainers of this project ask contributors to follow the [code of conduct](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md).\n\n## General Support Policy\n\nThe maintainers of this project provide limited support.\n\nYou can support the maintenance of this project by [sponsoring @localheinz](https://github.com/sponsors/localheinz) or [requesting an invoice for services related to this project](mailto:am@localheinz.com?subject=ergebnis/json-pointer:%20Requesting%20invoice%20for%20services).\n\n## PHP Version Support Policy\n\nThis project supports PHP versions with [active and security support](https://www.php.net/supported-versions.php).\n\nThe maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.\n\n## Security Policy\n\nThis project has a [security policy](.github/SECURITY.md).\n\n## License\n\nThis project uses the [MIT license](LICENSE.md).\n\n## Social\n\nFollow [@localheinz](https://twitter.com/intent/follow?screen_name=localheinz) and [@ergebnis](https://twitter.com/intent/follow?screen_name=ergebnis) on Twitter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fergebnis%2Fjson-pointer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fergebnis%2Fjson-pointer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fergebnis%2Fjson-pointer/lists"}