File tree Expand file tree Collapse file tree 1 file changed +82
-0
lines changed
Expand file tree Collapse file tree 1 file changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ # JSONPointer
2+
3+ [ ![ Build Status] ( https://github.com/stefna/json-pointer/actions/workflows/continuous-integration.yml/badge.svg?branch=main )] ( https://github.com/stefna/di/actions/workflows/continuous-integration.yml )
4+ [ ![ Latest Version on Packagist] ( https://img.shields.io/packagist/v/stefna/di.svg )] ( https://packagist.org/packages/stefna/di )
5+ [ ![ Software License] ( https://img.shields.io/github/license/stefna/di.svg )] ( LICENSE )
6+
7+ JSON Pointer implementation
8+
9+ Inspired by https://github.com/gamringer/JSONPointer
10+
11+ ## Requirements
12+
13+ PHP 8.2 or higher.
14+
15+ ## Installation
16+
17+ ```
18+ composer require stefna/json-pointer
19+ ```
20+
21+ # Usage
22+
23+ ## Test if document has pointer
24+
25+ ``` php
26+
27+ $document = [
28+ "foo" => ["bar", "baz"],
29+ "qux" => "quux"
30+ ];
31+
32+ $document = new \JsonPointer\BasicDocument('test', $document);
33+
34+ var_dump($document->has('/foo'));
35+
36+ var_dump($document->has('/foo/bar'));
37+
38+ /* Results:
39+
40+ bool(true)
41+ bool(false)
42+
43+ */
44+ ```
45+
46+ ## Retrieving value form document
47+
48+ ``` php
49+
50+ $document = [
51+ "foo" => ["bar", "baz"],
52+ "qux" => "quux"
53+ ];
54+
55+ $document = new \JsonPointer\BasicDocument('test', $document);
56+
57+ var_dump($document->get('/foo'));
58+
59+ var_dump($document->get('/foo/bar'));
60+ /* Result
61+
62+ array(2) {
63+ [0] =>
64+ string(3) "bar"
65+ [1] =>
66+ string(3) "baz"
67+ }
68+
69+ Throws JSONPointer\Exceptions\Reference - Referenced element does not exist: bar
70+
71+ */
72+ ```
73+
74+
75+ ## Contribute
76+
77+ We are always happy to receive bug/security reports and bug/security fixes
78+
79+ ## License
80+
81+ The MIT License (MIT). Please see [ License File] ( LICENSE.md ) for more information.
82+
You can’t perform that action at this time.
0 commit comments