Skip to content

Commit 6a6df64

Browse files
committed
docs: README examples and links
1 parent 30f3cb1 commit 6a6df64

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h1 align="center">Python JSONPath</h1>
22

33
<p align="center">
4-
A flexible JSONPath engine for Python.
4+
A flexible JSONPath engine for Python with JSON Pointer and JSON Patch.
55
</p>
66

77
<p align="center">
@@ -92,29 +92,17 @@ print(user_names) # ['John', 'Sally', 'Jane']
9292

9393
### JSON Pointer
9494

95-
Since version 0.8.0, we also include an [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901) compliant implementation of JSON Pointer.
95+
Since version 0.8.0, we include an [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901) compliant implementation of JSON Pointer. See JSON Pointer [quick start](https://jg-rp.github.io/python-jsonpath/quickstart/#pointerresolvepointer-data), [guide](https://jg-rp.github.io/python-jsonpath/pointers/) and [API reference](https://jg-rp.github.io/python-jsonpath/api/#jsonpath.JSONPointer)
9696

9797
```python
9898
from jsonpath import pointer
9999

100100
data = {
101101
"users": [
102-
{
103-
"name": "Sue",
104-
"score": 100,
105-
},
106-
{
107-
"name": "John",
108-
"score": 86,
109-
},
110-
{
111-
"name": "Sally",
112-
"score": 84,
113-
},
114-
{
115-
"name": "Jane",
116-
"score": 55,
117-
},
102+
{"name": "Sue", "score": 100},
103+
{"name": "John", "score": 86},
104+
{"name": "Sally", "score": 84},
105+
{"name": "Jane", "score": 55},
118106
]
119107
}
120108

@@ -125,6 +113,26 @@ jane_score = pointer.resolve(["users", 3, "score"], data)
125113
print(jane_score) # 55
126114
```
127115

116+
### JSON Patch
117+
118+
Since version 0.8.0, we also include an [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) compliant implementation of JSON Patch. See JSON Patch [quick start](https://jg-rp.github.io/python-jsonpath/quickstart/#patchapplypatch-data) and [API reference](https://jg-rp.github.io/python-jsonpath/api/#jsonpath.JSONPatch)
119+
120+
```python
121+
from jsonpath import patch
122+
123+
patch_operations = [
124+
{"op": "add", "path": "/some/foo", "value": {"foo": {}}},
125+
{"op": "add", "path": "/some/foo", "value": {"bar": []}},
126+
{"op": "copy", "from": "/some/other", "path": "/some/foo/else"},
127+
{"op": "add", "path": "/some/foo/bar/-", "value": 1},
128+
]
129+
130+
data = {"some": {"other": "thing"}}
131+
patch.apply(patch_operations, data)
132+
print(data) # {'some': {'other': 'thing', 'foo': {'bar': [1], 'else': 'thing'}}}
133+
134+
```
135+
128136
## License
129137

130138
`python-jsonpath` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

0 commit comments

Comments
 (0)