You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,12 @@
1
1
# Python JSONPath RFC 9535 Change Log
2
2
3
+
## Version 0.2.0 (unreleased)
4
+
5
+
**Features**
6
+
7
+
- Added `JSONPathNode.parent`, a reference the the node's parent node. See [#21](https://github.com/jg-rp/python-jsonpath-rfc9535/issues/21).
8
+
- Changed `JSONPathNode.value` to be a `@property` and `setter`. When assigning to `JSONPathNode.value`, source data is updated too. See [#21](https://github.com/jg-rp/python-jsonpath-rfc9535/issues/21).
Copy file name to clipboardExpand all lines: README.md
+24-6Lines changed: 24 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,16 +116,16 @@ Apply JSONPath expression _query_ to _value_. _value_ should arbitrary, possible
116
116
117
117
A list of `JSONPathNode` instances is returned, one node for each value matched by _query_. The returned list will be empty if there were no matches.
118
118
119
-
Each `JSONPathNode` has:
119
+
Each `JSONPathNode` has properties:
120
120
121
-
-a `value`property, which is the JSON-like value associated with the node.
122
-
-a `location`property, which is a tuple of property names and array/list indexes that were required to reach the node's value in the target JSON document.
123
-
-a `path()` method, which returns the normalized path to the node in the target JSON document.
121
+
-`value`- The JSON-like value associated with the node.
122
+
-`location`- A tuple of property names and array/list indexes that were required to reach the node's value in the target JSON document.
123
+
-`parent` (_New in version 0.2.0_) - The node's parent node, or `None` if the current node is the root.
124
124
125
125
```python
126
126
import jsonpath_rfc9535 as jsonpath
127
127
128
-
value= {
128
+
data= {
129
129
"users": [
130
130
{"name": "Sue", "score": 100},
131
131
{"name": "John", "score": 86, "admin": True},
@@ -135,18 +135,36 @@ value = {
135
135
"moderator": "John",
136
136
}
137
137
138
-
for node in jsonpath.find("$.users[?@.score > 85]", value):
# {'name': 'Sue', 'score': 100} at '$['users'][0]'
142
144
# {'name': 'John', 'score': 86, 'admin': True} at '$['users'][1]'
143
145
```
144
146
147
+
`JSONPathNode.path()` returns the normalized path to the node in the target JSON document.
148
+
145
149
`JSONPathNodeList` is a subclass of `list` with some helper methods.
146
150
147
151
-`values()` returns a list of values, one for each node.
148
152
-`items()` returns a list of `(normalized path, value)` tuples.
149
153
154
+
**_New in version 0.2.0_**
155
+
156
+
Assigning to `JSONPathNode.value` will update the node's value **and mutate source data**. Beware,updating data after evaluating a query can invalidate existing child node paths.
0 commit comments