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: src/components/data/reference.json
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -58,9 +58,9 @@
58
58
},
59
59
{
60
60
"name": "Operator",
61
-
"syntax": "(left operator right)",
62
-
"description": "JSON Query supports all basic <b>operators</b>. When composing multiple operators,\n it is necessary to use parentheses. Operators do not have precedence since\nparentheses are required.",
"description": "JSON Query supports all basic <b>operators</b>. Operators must have both a left and right hand side. To override the default precedence, an operator can be wrapped in parentheses <code>(...)</code>.",
|[Array](#arrays)|`[ item1, item2, ... ]`|`[ "New York", "Atlanta" ]`|
@@ -94,16 +94,16 @@ See page [Function reference](/reference) for a detailed overview of all availab
94
94
95
95
### Operators
96
96
97
-
JSON Query supports all basic operators. Operators must be wrapped in parentheses `(...)`, must have both a left and right hand side, and do not have precedence since parentheses are required. The syntax is:
97
+
JSON Query supports all basic operators. Operators must have both a left and right hand side. To override the default precedence, an operator can be wrapped in parentheses `(...)`. The syntax is:
98
98
99
99
```text
100
-
(left operator right)
100
+
left operator right
101
101
```
102
102
103
103
The following example tests whether a property `age` is greater than or equal to `18`:
104
104
105
105
```text
106
-
(.age >= 18)
106
+
.age >= 18
107
107
```
108
108
109
109
Operators are for example used to specify filter conditions:
@@ -112,12 +112,27 @@ Operators are for example used to specify filter conditions:
112
112
filter(.age >= 18)
113
113
```
114
114
115
-
When composing multiple operators, it is necessary to use parentheses:
115
+
When using multiple operators, they will be evaluated according to their precedence (highest first):
116
116
117
117
```text
118
-
filter((.age >= 18) and (.age <= 65))
118
+
filter(.age >= 18 and .age <= 65)
119
119
```
120
120
121
+
Note that some operators, like `and`, `or`, `+`, and `-`, support more than two values and are evaluated left-to-right, like `2 + 3 + 4`. Others, like `^` and `==`, do not support more than two values. If needed, it is always possible to use parenthesis, like `(2 ^ 3) ^ 4`.
122
+
123
+
The operators have the following precedence, from highest to lowest:
Copy file name to clipboardExpand all lines: src/content/reference.md
+23-18Lines changed: 23 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -173,7 +173,7 @@ jsonquery(data, 'filter((.age > 30) and (.address.city == "New York"))')
173
173
174
174
## sort
175
175
176
-
Sort a list with objects or values.
176
+
Sort a list with objects or values. The function first orders values by type: `boolean`, `number`, `string`, and other types. Strings are compared alphabetically and case-sensitive. Objects and arrays are not re-ordered.
Test whether two values are strictly equal. This will consider a string `"2"` and a number `2` to be _not_ equal for example since their data type differs.
714
+
Test whether two values are deep strict equal. This will consider a string `"2"` and a number `2` to be _not_ equal for example, since their data type differs. Objects and arrays are compared recursively, so `{"id":1,"name":"Joe"}` and `{"name":"Joe","id":1}` are deep equal for example.
Test whether `a` is greater than `b`. The operator supports comparing two numbers, two strings, or two booleans. In case of unsupported data types or mixed data types, the function returns `false.
Test whether `a` is greater than or equal to `b`. The operator supports comparing two numbers, two strings, or two booleans. In case of unsupported data types or mixed data types, the function returns `false.
Test whether `a` is less than `b`. The operator supports comparing two numbers, two strings, or two booleans. In case of unsupported data types or mixed data types, the function returns `false.
Test whether `a` is less than or equal to `b`. The operator supports comparing two numbers, two strings, or two booleans. In case of unsupported data types or mixed data types, the function returns `false.
Test whether two values are not equal. This is the opposite of the strict equal function `eq`. Two values are considered unequal when their data type differs (for example one is a string and another is a number), or when the value itself is different. For example a string `"2"` and a number `2` are considered unequal, even though their mathematical value is equal.
843
+
Test whether two values are not deep strict equal. This is the opposite of the strict equal function `eq`. Two values are considered unequal when their data type differs (for example one is a string and another is a number), or when the value itself is different. For example a string `"2"` and a number `2` are considered unequal, even though their mathematical value is equal. Objects and arrays are compared recursively, so `{"id":1,"name":"Joe"}` and `{"name":"Joe","id":1}` are deep equal for example.
843
844
844
845
```text
845
846
a != b
@@ -868,11 +869,13 @@ jsonquery({ a: 2 }, 'a != "2"') // true (since not strictly equal)
868
869
869
870
## and
870
871
871
-
Test whether both values are truthy. A non-truthy value is any of `false`, `0`, `""`, `null`, or `undefined`.
872
+
Test whether two or more values are truthy. A non-truthy value is any of `false`, `0`, `""`, `null`, or `undefined`. The function throws an error in case of zero arguments.
Test whether one or both values are truthy. A non-truthy value is any of `false`, `0`, `""`, `null`, or `undefined`.
898
+
Test whether at least one of the values is truthy. A non-truthy value is any of `false`, `0`, `""`, `null`, or `undefined`. The function throws an error in case of zero arguments.
Test whether the search value is one of the values of the provided list.
1005
+
Test whether the search value is one of the values of the provided list. Values are compared using the `eq` operator, which does a deep strict equal comparison.
1001
1006
1002
1007
```text
1003
1008
searchValue in values
@@ -1022,7 +1027,7 @@ jsonquery(data, 'filter(.age in [16, 18])')
1022
1027
1023
1028
## not in
1024
1029
1025
-
Test whether the search value is _not_ one of the values of the provided list.
1030
+
Test whether the search value is _not_ one of the values of the provided list. Values are compared using the `eq` operator, which does a deep strict equal comparison.
Calculate the exponent. Returns the result of raising `a` to the power of `b`, like `a^b`
1163
+
Calculate the exponent. Returns the result of raising `a` to the power of `b`, like `a ^ b`. The `^` operator does not support more than two values, so if you need to calculate a chain of multiple exponents you'll have to use parenthesis, like `(a ^ b) ^ c`.
0 commit comments