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: docs/query.md
+128-1Lines changed: 128 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ for value in it.values():
82
82
83
83
## Tee
84
84
85
-
And finally there's `tee()`, which creates multiple independent queries from one query iterator. It is not safe to use the initial `Query` instance after calling `tee()`.
85
+
[`tee()`](api.md#jsonpath.Query.tee) creates multiple independent queries from one query iterator. It is not safe to use the initial `Query` instance after calling `tee()`.
[`select(*expressions, projection=Projection.RELATIVE)`](api.md/#jsonpath.Query.select) performs JSONPath match projection, selecting a subset of values according to one or more JSONPath query expressions relative to the match location. For example:
99
+
100
+
```python
101
+
from jsonpath import query
102
+
103
+
data = {
104
+
"categories": [
105
+
{
106
+
"name": "footwear",
107
+
"products": [
108
+
{
109
+
"title": "Trainers",
110
+
"description": "Fashionable trainers.",
111
+
"price": 89.99,
112
+
},
113
+
{
114
+
"title": "Barefoot Trainers",
115
+
"description": "Running trainers.",
116
+
"price": 130.00,
117
+
"social": {"likes": 12, "shares": 7},
118
+
},
119
+
],
120
+
},
121
+
{
122
+
"name": "headwear",
123
+
"products": [
124
+
{
125
+
"title": "Cap",
126
+
"description": "Baseball cap",
127
+
"price": 15.00,
128
+
},
129
+
{
130
+
"title": "Beanie",
131
+
"description": "Winter running hat.",
132
+
"price": 9.00,
133
+
},
134
+
],
135
+
},
136
+
],
137
+
"price_cap": 10,
138
+
}
139
+
140
+
for product in query("$..products.*", data).select("title", "price"):
141
+
print(product)
142
+
```
143
+
144
+
Which selects just the `title` and `price` fields for each product.
145
+
146
+
```text
147
+
{'title': 'Trainers', 'price': 89.99}
148
+
{'title': 'Barefoot Trainers', 'price': 130.0}
149
+
{'title': 'Cap', 'price': 15.0}
150
+
{'title': 'Beanie', 'price': 9.0}
151
+
```
152
+
153
+
Without the call to `select()`, we'd get all fields in each product object.
154
+
155
+
```python
156
+
# ...
157
+
158
+
for product in query("$..products.*", data).values():
0 commit comments