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: README.md
+48-2Lines changed: 48 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ Each `JSONPathNode` has:
41
41
The returned list is a subclass of `list` with some helper methods.
42
42
43
43
-`values()` returns a list of values, one for each node.
44
-
-`values_or_singular()` returns a scalar value if the list has exactly one node, or a list of values otherwise.
44
+
-`items()` returns a list of `(normalized path, value)` tuples, one tuple for each node in the list.
45
45
46
46
**Example:**
47
47
@@ -65,10 +65,56 @@ for node in jsonpath.find("$.users[?@.score > 85]", value):
65
65
# {'name': 'John', 'score': 86, 'admin': True} at '$['users'][1]'
66
66
```
67
67
68
-
### finditer(query, value)
68
+
### `finditer(query, value)`
69
69
70
70
`finditer()` accepts the same arguments as [`find()`](#findquery-value), but returns an iterator over `JSONPathNode` instances rather than a list. This could be useful if you're expecting a large number of results that you don't want to load into memory all at once.
71
71
72
+
### `find_one(query, value)`
73
+
74
+
`find_one()` accepts the same arguments as [`find()`](#findquery-value), but returns the first available `JSONPathNode`, or `None` if there were no matches.
75
+
76
+
`find_one()` is equivalent to:
77
+
78
+
```python
79
+
deffind_one(query, value):
80
+
try:
81
+
returnnext(iter(jsonpath.finditer(query, value)))
82
+
exceptStopIteration:
83
+
returnNone
84
+
```
85
+
86
+
### `compile(query)`
87
+
88
+
`find(query, value)` is a convenience function for `JSONPathEnvironment().compile(query).apply(value)`. Use `compile(query)` to obtain a `JSONPathQuery` instance which can be applied to difference JSON-like values repeatedly.
0 commit comments