File tree 2 files changed +84
-0
lines changed
2 files changed +84
-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/json-pointer/actions/workflows/continuous-integration.yml )
4
+ [ ![ Latest Version on Packagist] ( https://img.shields.io/packagist/v/stefna/json-pointer.svg )] ( https://packagist.org/packages/json-pointer )
5
+ [ ![ Software License] ( https://img.shields.io/github/license/json-pointer.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
+
61
+ /* Result
62
+
63
+ array(2) {
64
+ [0] =>
65
+ string(3) "bar"
66
+ [1] =>
67
+ string(3) "baz"
68
+ }
69
+
70
+ Throws JSONPointer\Exceptions\Reference - Referenced element does not exist: bar
71
+
72
+ */
73
+ ```
74
+
75
+
76
+ ## Contribute
77
+
78
+ We are always happy to receive bug/security reports and bug/security fixes
79
+
80
+ ## License
81
+
82
+ The MIT License (MIT). Please see [ License File] ( LICENSE.md ) for more information.
83
+
Original file line number Diff line number Diff line change 2
2
"name" : " stefna/json-pointer" ,
3
3
"description" : " " ,
4
4
"type" : " library" ,
5
+ "license" : " MIT" ,
5
6
"authors" : [
6
7
{
7
8
"name" : " Andreas Sundqvist" ,
You can’t perform that action at this time.
0 commit comments