Skip to content

Commit 2e9a2d3

Browse files
committed
docs: describe support for multiple values in operators
1 parent 970112f commit 2e9a2d3

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ When using multiple operators, they will be evaluated according to their precede
208208
filter(.age >= 18 and .age <= 65)
209209
```
210210

211+
Note that some operators, like `and`, `or`, `+`, and `-`, support more than two values, 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`.
212+
211213
The operators have the following precedence, from highest to lowest:
212214

213215
- `|`

reference/functions.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -869,11 +869,13 @@ jsonquery({ a: 2 }, 'a != "2"') // true (since not strictly equal)
869869

870870
## and
871871

872-
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`.
873873

874874
```text
875875
a and b
876+
a and b and c and ...
876877
and(a, b)
878+
and(a, b, c, ...)
877879
```
878880

879881
Examples:
@@ -893,11 +895,13 @@ jsonquery(data, 'filter((.name == "Chris") and (.age == 16))')
893895

894896
## or
895897

896-
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`.
897899

898900
```text
899901
a or b
902+
a or b or c or ...
900903
or(a, b)
904+
or(a, b, c, ...)
901905
```
902906

903907
Examples:
@@ -1081,11 +1085,13 @@ jsonquery(data, 'filter(regex(.message, "like|awesome", "i"))')
10811085

10821086
## add (`+`)
10831087

1084-
Add two values.
1088+
Add two or more values. The operator is left associative.
10851089

10861090
```text
10871091
a + b
1092+
a + b + c + ...
10881093
add(a, b)
1094+
add(a, b, c, ...)
10891095
```
10901096

10911097
Examples:
@@ -1105,11 +1111,13 @@ jsonquery(user, '(.firstName + " ") + .lastName')
11051111

11061112
## subtract (`-`)
11071113

1108-
Subtract two values.
1114+
Subtract two or more values. The operator is left associative.
11091115

11101116
```text
11111117
a - b
1118+
a - b - c - ...
11121119
subtract(a, b)
1120+
subtract(a, b, c, ...)
11131121
```
11141122

11151123
Examples:
@@ -1122,11 +1130,13 @@ jsonquery(data, '.a - .b') // 4
11221130

11231131
## multiply (`*`)
11241132

1125-
Multiply two values.
1133+
Multiply two or more values. The operator is left associative.
11261134

11271135
```text
11281136
a * b
1137+
a * b * c * ...
11291138
multiply(a, b)
1139+
multiply(a, b, c, ...)
11301140
```
11311141

11321142
Examples:
@@ -1139,11 +1149,13 @@ jsonquery(data, '.a * .b') // 12
11391149

11401150
## divide (`/`)
11411151

1142-
Divide two values.
1152+
Divide two or more values. The operator is left associative.
11431153

11441154
```text
11451155
a / b
1156+
a / b / c / ...
11461157
divide(a, b)
1158+
divide(a, b, c, ...)
11471159
```
11481160

11491161
Examples:
@@ -1156,7 +1168,7 @@ jsonquery(data, '.a / .b') // 3
11561168

11571169
## pow (`^`)
11581170

1159-
Calculate the exponent. Returns the result of raising `a` to the power of `b`, like `a^b`
1171+
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`.
11601172

11611173
```text
11621174
a ^ b
@@ -1173,7 +1185,7 @@ jsonquery(data, '.a ^ .b') // 8
11731185

11741186
## mod (`%`)
11751187

1176-
Calculate the remainder (the modulus) of `a` divided by `b`, like `a % b`.
1188+
Calculate the remainder (the modulus) of `a` divided by `b`, like `a % b`. The modulus operator does not support more than two values, so if you need to calculate a chain of multiple modulus operators you'll have to use parenthesis, like `(a % b) % c`.
11771189

11781190
```text
11791191
a % b

0 commit comments

Comments
 (0)