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/advanced.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
Arbitrary variables can be made available to [filter expressions](syntax.md#filters-expression) using the _filter_context_ argument to [`findall()`](quickstart.md#findallpath-data) and [`finditer()`](quickstart.md#finditerpath-data). _filter_context_ should be a [mapping](https://docs.python.org/3/library/typing.html#typing.Mapping) of strings to JSON-like objects, like lists, dictionaries, strings and integers.
6
6
7
-
Filter context variables are selected using the _filter context selector_, which defaults to `_` and has usage similar to `$` and `@`.
7
+
Filter context variables are selected using a filter query starting with the _filter context identifier_, which defaults to `_` and has usage similar to `$` and `@`.
Copy file name to clipboardExpand all lines: docs/syntax.md
+12-6
Original file line number
Diff line number
Diff line change
@@ -122,7 +122,7 @@ $...title
122
122
123
123
### Filters (`[?EXPRESSION]`)
124
124
125
-
Filters allow you to remove nodes from a selection using a Boolean expression. When filtering a mapping-like object, `#` references the current key/property and `@` references the current value associated with `#`. When filtering a sequence-like object, `@` references the current item and `#` will hold the item's index in the sequence.
125
+
Filters allow you to remove nodes from a selection using a Boolean expression. A _filter query_ is a JSONPath query nested within a filter expression. Every filter query must start with the root identifier (`$`), the current node identifier (`@`) or the [filter context](advanced.md#filter-variables) identifier (`_`).
When filtering a mapping-like object, `#` references the current key/property and `@` references the current value associated with `#`. When filtering a sequence-like object, `@` references the current item and `#` will hold the item's index in the sequence.
136
+
135
137
Comparison operators include `==`, `!=`, `<`, `>`, `<=` and `>=`. Plus `<>` as an alias for `!=`.
136
138
137
139
`in` and `contains` are membership operators. `left in right` is equivalent to `right contains left`.
138
140
139
-
`&&` and `||` are logical operators,`and` and `or` work too.
141
+
`&&` and `||` are logical operators and terms can be grouped with parentheses.`and` and `or` work too.
140
142
141
143
`=~` matches the left value with a regular expression literal. Regular expressions use a syntax similar to that found in JavaScript, where the pattern to match is surrounded by slashes, optionally followed by flags.
142
144
143
145
```text
144
146
$..products[?(@.description =~ /.*trainers/i)]
145
147
```
146
148
147
-
Filter expressions can call predefined [function extensions](functions.md) too.
149
+
A filter query on its own - one that is not part of a comparison expression - is an existence test. We also support comparing a filter query to the special `undefined` keyword. These two example are equivalent.
`undefined` can be used to filter on the absence of a key/property or an undefined value returned from a filter function. `missing` is an alias for `undefined`.
Filter expressions can call predefined [function extensions](functions.md) too.
160
+
161
+
```text
162
+
$.categories[?count(@.products.*) >= 2]
163
+
```
164
+
159
165
### Union (`|`) and intersection (`&`)
160
166
161
167
Union (`|`) and intersection (`&`) are similar to Python's set operations, but we don't dedupe the matches (matches will often contain unhashable objects).
0 commit comments