Skip to content
Myr

Improve manual in various ways (inputs, sort_by, foreach sections, etc.) (#2744)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Add error/0 and mentions null input behavior (close #2231) - Explain value iterator suffix syntax .foo[] (close #1047) - Mention array slicing is also zero-based (close #2094) - Add examples of input and inputs filters (close #2216, close #2470) - Improve sort_by about multiple values (close #2103, close #2467, close #2474) - Improve foreach section and simplify examples (close #1148, close #2169) - Fix recurse/1 document on how it is identical using recurse/2 (close #2036, close #2412) - Add non-string examples of index/1, rindex/1 (close #1422) - Simplify the example of truncate_stream/1 (close #1736)

authored by itchyny · committed by GitHub · parent 1cf6515 · Browse files · 9 files+698 added−302 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+698 added−302 removed

  • tests:+89 added−12 removed
  • other:+609 added−290 removed

9 files+698 added−302 removed

modified:docs/content/download/default.yml+1 added-1 removed
153 unmodified lines
154155 You can build it using the usual `./configure && make && sudo156 make install` rigmarole.157158 If you're interested in using the lastest development version, try:158 If you're interested in using the latest development version, try:159160 git clone --recursive https://github.com/jqlang/jq.git161 cd jq162 autoreconf -i
45 unmodified lines
modified:docs/content/manual/v1.3/manual.yml+20 added-21 removed
74 unmodified lines
7576 jq filters run on a stream of JSON data. The input to jq is77 parsed as a sequence of whitespace-separated JSON values which78 are passed through the provided filter one at a time. The79 output(s) of the filter are written to standard out, again as a80 sequence of whitespace-separated JSON data.79 output(s) of the filter are written to standard output, as a80 sequence of newline-separated JSON data.8182 You can affect how jq reads and writes its input and output83 using some command-line options:84
86 unmodified lines
171 body: |172173 You can also look up fields of an object using syntax like174 `.["foo"]` (`.foo` above is a shorthand version of this). This175 one works for arrays as well, if the key is an176 integer. Arrays are zero-based (like javascript), so `.[2]`177 returns the third element of the array.175 one works for arrays as well, if the key is an integer. Arrays176 are zero-based, so `.[2]` returns the third element of the array.177178 The `.[10:15]` syntax can be used to return a subarray of an179 array. The array returned by `.[10:15]` will be of length 5,180 containing the elements from index 10 (inclusive) to index
96 unmodified lines
277 strings, booleans, arrays, objects (which in JSON-speak are278 hashes with only string keys), and "null".279280 Booleans, null, strings and numbers are written the same way as282 in javascript. Just like everything else in jq, these simple281 in JSON. Just like everything else in jq, these simple282 values take an input and produce an output - `42` is a valid jq283 expression that takes an input, ignores it, and returns 42284 instead.285
619 unmodified lines
905 "truthiness" than is found in JavaScript or Python, but it906 means that you'll sometimes have to be more explicit about907 the condition you want: you can't test whether, e.g. a908 string is empty using `if .name then A else B end`, you'll910 need something more like `if (.name | count) > 0 then A else909 need something more like `if (.name | length) > 0 then A else910 B end` instead.911912 If the condition `A` produces multiple results, then `B` is evaluated913 once for each result that is not false or null, and `C` is evaluated
124 unmodified lines
1038 simply `add / length` - the `add` expression is given the array and1039 produces its sum, and the `length` expression is given the array and1040 produces its length.10411043 So, there's generally a cleaner way to solve most problems in jq that1042 So, there's generally a cleaner way to solve most problems in jq than1043 defining variables. Still, sometimes they do make things easier, so jq1044 lets you define variables using `expression as $variable`. All1045 variable names start with `$`. Here's a slightly uglier version of the1046 array-averaging example:
79 unmodified lines
1126 - program: 'def addvalue(f): f as $x | map(. + $x); addvalue(.[0])'1127 input: '[[1,2],[10,20]]'1128 output: ['[[1,2,1,2], [10,20,1,2]]']11291131 - title: Reduce1130 - title: "`reduce`"1131 body: |11321134 The `reduce` syntax in jq allows you to combine all of the1135 results of an expression by accumulating them into a single1136 answer. As an example, we'll pass `[3,2,1]` to this expression:1133 The `reduce` syntax allows you to combine all of the results of1134 an expression by accumulating them into a single answer.1135 The form is `reduce EXP as $var (INIT; UPDATE)`.1136 As an example, we'll pass `[1,2,3]` to this expression:11371138 reduce .[] as $item (0; . + $item)11391140 For each result that `.[]` produces, `. + $item` is run to1141 accumulate a running total, starting from 0. In this1142 example, `.[]` produces the results 3, 2, and 1, so the1143 effect is similar to running something like this:1141 accumulate a running total, starting from 0 as the input value.1142 In this example, `.[]` produces the results `1`, `2`, and `3`,1143 so the effect is similar to running something like this:11441145 0 | (3 as $item | . + $item) |1146 (2 as $item | . + $item) |1147 (1 as $item | . + $item)1145 0 | 1 as $item | . + $item |1146 2 as $item | . + $item |1147 3 as $item | . + $item11481149 examples:1150 - program: 'reduce .[] as $item (0; . + $item)'1151 input: '[10,2,5,3]'1152 output: ['20']1151 input: '[1,2,3,4,5]'1152 output: ['15']115311541154 - title: Assignment1155 body: |11561157 Assignment works a little differently in jq than in most
107 unmodified lines
modified:docs/content/manual/v1.4/manual.yml+19 added-20 removed
74 unmodified lines
7576 jq filters run on a stream of JSON data. The input to jq is77 parsed as a sequence of whitespace-separated JSON values which78 are passed through the provided filter one at a time. The79 output(s) of the filter are written to standard out, again as a80 sequence of whitespace-separated JSON data.79 output(s) of the filter are written to standard output, as a80 sequence of newline-separated JSON data.8182 Note: it is important to mind the shell's quoting rules. As a83 general rule it's best to always quote (with single-quote84 characters) the jq program, as too many characters with special
167 unmodified lines
252 body: |253254 You can also look up fields of an object using syntax like255 `.["foo"]` (`.foo` above is a shorthand version of this). This256 one works for arrays as well, if the key is an257 integer. Arrays are zero-based (like javascript), so `.[2]`258 returns the third element of the array.256 one works for arrays as well, if the key is an integer. Arrays257 are zero-based, so `.[2]` returns the third element of the array.258259 The `.[10:15]` syntax can be used to return a subarray of an260 array or substring of a string. The array returned by261 `.[10:15]` will be of length 5, containing the elements from262 index 10 (inclusive) to index 15 (exclusive). Either index may263 be negative (in which case it counts backwards from the end of264 the array), or omitted (in which case it refers to the start266 or end of the array).265 or end of the array). Indices are zero-based.266267 The `?` "operator" can also be used with the slice operator,268 as in `.[10:15]?`, which outputs values where the inputs are269 slice-able.
103 unmodified lines
373 strings, booleans, arrays, objects (which in JSON-speak are374 hashes with only string keys), and "null".375376 Booleans, null, strings and numbers are written the same way as378 in javascript. Just like everything else in jq, these simple377 in JSON. Just like everything else in jq, these simple378 values take an input and produce an output - `42` is a valid jq379 expression that takes an input, ignores it, and returns 42380 instead.381
1146 unmodified lines
1528 - program: 'def addvalue(f): f as $x | map(. + $x); addvalue(.[0])'1529 input: '[[1,2],[10,20]]'1530 output: ['[[1,2,1,2], [10,20,1,2]]']15311533 - title: Reduce1532 - title: "`reduce`"1533 body: |15341536 The `reduce` syntax in jq allows you to combine all of the1537 results of an expression by accumulating them into a single1538 answer. As an example, we'll pass `[3,2,1]` to this expression:1535 The `reduce` syntax allows you to combine all of the results of1536 an expression by accumulating them into a single answer.1537 The form is `reduce EXP as $var (INIT; UPDATE)`.1538 As an example, we'll pass `[1,2,3]` to this expression:15391540 reduce .[] as $item (0; . + $item)15411542 For each result that `.[]` produces, `. + $item` is run to1543 accumulate a running total, starting from 0. In this1544 example, `.[]` produces the results 3, 2, and 1, so the1545 effect is similar to running something like this:1543 accumulate a running total, starting from 0 as the input value.1544 In this example, `.[]` produces the results `1`, `2`, and `3`,1545 so the effect is similar to running something like this:15461547 0 | (3 as $item | . + $item) |1548 (2 as $item | . + $item) |1549 (1 as $item | . + $item)1547 0 | 1 as $item | . + $item |1548 2 as $item | . + $item |1549 3 as $item | . + $item15501551 examples:1552 - program: 'reduce .[] as $item (0; . + $item)'1553 input: '[10,2,5,3]'1554 output: ['20']1553 input: '[1,2,3,4,5]'1554 output: ['15']155515561556 - title: Assignment1557 body: |15581559 Assignment works a little differently in jq than in most
107 unmodified lines
modified:docs/content/manual/v1.5/manual.yml+126 added-62 removed
76 unmodified lines
7778 jq filters run on a stream of JSON data. The input to jq is79 parsed as a sequence of whitespace-separated JSON values which80 are passed through the provided filter one at a time. The81 output(s) of the filter are written to standard out, again as a82 sequence of whitespace-separated JSON data.81 output(s) of the filter are written to standard output, as a82 sequence of newline-separated JSON data.8384 Note: it is important to mind the shell's quoting rules. As a85 general rule it's best to always quote (with single-quote86 characters) the jq program, as too many characters with special
231 unmodified lines
318 body: |319320 You can also look up fields of an object using syntax like321 `.["foo"]` (`.foo` above is a shorthand version of this). This322 one works for arrays as well, if the key is an323 integer. Arrays are zero-based (like javascript), so `.[2]`324 returns the third element of the array.322 one works for arrays as well, if the key is an integer. Arrays323 are zero-based, so `.[2]` returns the third element of the array.324325 The `.[10:15]` syntax can be used to return a subarray of an326 array or substring of a string. The array returned by327 `.[10:15]` will be of length 5, containing the elements from328 index 10 (inclusive) to index 15 (exclusive). Either index may329 be negative (in which case it counts backwards from the end of330 the array), or omitted (in which case it refers to the start332 or end of the array).331 or end of the array). Indices are zero-based.332333 The `.[2]` syntax can be used to return the element at the334 given index. Negative indices are allowed, with -1 referring335 to the last element, -2 referring to the next to last element,
44 unmodified lines
380 If you use the `.[index]` syntax, but omit the index381 entirely, it will return *all* of the elements of an382 array. Running `.[]` with the input `[1,2,3]` will produce the383 numbers as three separate results, rather than as a single385 array.384 array. A filter of the form `.foo[]` is equivalent to385 `.foo | .[]`.386387 You can also use this on an object, and it will return all388 the values of the object.389
7 unmodified lines
397 - program: '.[]'398 input: '[]'399 output: []400401 - program: '.foo[]'402 input: '{"foo":[1,2,3]}'403 output: ['1','2','3']404405 - program: '.[]'406 input: '{"a": 1, "b": 1}'407 output: ['1', '1']408409 - title: "`.[]?`"410 body: |411412 Like `.[]`, but no errors will be output if . is not an array409 or object.413 or object. A filter of the form `.foo[]?` is equivalent to414 `.foo | .[]?`.415416 - title: "`,`"417 body: |418
41 unmodified lines
460 strings, booleans, arrays, objects (which in JSON-speak are461 hashes with only string keys), and "null".462463 Booleans, null, strings and numbers are written the same way as459 in javascript. Just like everything else in jq, these simple464 in JSON. Just like everything else in jq, these simple465 values take an input and produce an output - `42` is a valid jq466 expression that takes an input, ignores it, and returns 42467 instead.468
378 unmodified lines
847 - program: '[1,2,empty,3]'848 input: 'null'849 output: ['[1,2,3]']850846 - title: "`error(message)`"851 - title: "`error`, `error(message)`"852 body: |853849 Produces an error, just like `.a` applied to values other than850 null and objects would, but with the given message as the851 error's value.854 Produces an error with the input value, or with the message855 given as the argument. Errors can be caught with try/catch;856 see below.857858 When the error value is `null`, it produces nothing and works859 just like `empty`. So `[null | error]` and `[error(null)]` both860 emit `[]`.861862 examples:863 - program: 'try error catch .'864 input: '"error message"'865 output: ['"error message"']866867 - program: 'try error("invalid value: \(.)") catch .'868 input: '42'869 output: ['"invalid value: 42"']870871 - title: "`$__loc__`"872 body: |873874 Produces an object with a "file" key and a "line" key, with
147 unmodified lines
1022 - program: flatten1023 input: '[{"foo": "bar"}, [{"foo": "baz"}]]'1024 output: ['[{"foo": "bar"}, {"foo": "baz"}]']10251008 - title: "`range(upto)`, `range(from; upto)` `range(from; upto; by)`"1026 - title: "`range(upto)`, `range(from; upto)`, `range(from; upto; by)`"1027 body: |10281029 The `range` function produces a range of numbers. `range(4; 10)`1030 produces 6 numbers, from 4 (inclusive) to 10 (exclusive). The numbers
127 unmodified lines
1158 compared by comparing their sets of keys (as arrays in1159 sorted order), and if their keys are equal then the values1160 are compared key by key.11611144 `sort` may be used to sort by a particular field of an1145 object, or by applying any jq filter.1162 `sort_by` may be used to sort by a particular field of an1163 object, or by applying any jq filter. `sort_by(f)` compares1164 two elements by comparing the result of `f` on each element.1165 When `f` produces multiple values, it firstly compares the1166 first values, and the second values if the first values are1167 equal, and so on.11681147 `sort_by(f)` compares two elements by comparing the result of1148 `f` on each element.11491169 examples:1170 - program: 'sort'1171 input: '[8,3,null,6]'1172 output: ['[null,3,6,8]']11731174 - program: 'sort_by(.foo)'1155 input: '[{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]'1156 output: ['[{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]']1175 input: '[{"foo":4, "bar":10}, {"foo":3, "bar":10}, {"foo":2, "bar":1}]'1176 output: ['[{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":4, "bar":10}]']11771178 - program: 'sort_by(.foo, .bar)'1179 input: '[{"foo":4, "bar":10}, {"foo":3, "bar":20}, {"foo":2, "bar":1}, {"foo":3, "bar":10}]'1180 output: ['[{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":3, "bar":20}, {"foo":4, "bar":10}]']11811182 - title: "`group_by(path_expression)`"1183 body: |11841185 `group_by(.foo)` takes as input an array, groups the
117 unmodified lines
1303 examples:1304 - program: 'index(", ")'1305 input: '"a,b, cd, efg, hijk"'1306 output: ['3']1307 - program: 'index(1)'1308 input: '[0,1,2,1,3,1,4]'1309 output: ['1']1310 - program: 'index([1,2])'1311 input: '[0,1,2,3,1,4,2,5,1,2,6,7]'1312 output: ['1']1313 - program: 'rindex(", ")'1314 input: '"a,b, cd, efg, hijk"'1315 output: ['12']1316 - program: 'rindex(1)'1317 input: '[0,1,2,1,3,1,4]'1318 output: ['5']1319 - program: 'rindex([1,2])'1320 input: '[0,1,2,3,1,4,2,5,1,2,6,7]'1321 output: ['8']13221323 - title: "`inside`"1324 body: |1325
1017 unmodified lines
2343 - program: 'def addvalue(f): f as $x | map(. + $x); addvalue(.[0])'2344 input: '[[1,2],[10,20]]'2345 output: ['[[1,2,1,2], [10,20,1,2]]']23462311 - title: Reduce2312 body: |23132314 The `reduce` syntax in jq allows you to combine all of the2315 results of an expression by accumulating them into a single2316 answer. As an example, we'll pass `[3,2,1]` to this expression:23172318 reduce .[] as $item (0; . + $item)23192320 For each result that `.[]` produces, `. + $item` is run to2321 accumulate a running total, starting from 0. In this2322 example, `.[]` produces the results 3, 2, and 1, so the2323 effect is similar to running something like this:23242325 0 | (3 as $item | . + $item) |2326 (2 as $item | . + $item) |2327 (1 as $item | . + $item)23282329 examples:2330 - program: 'reduce .[] as $item (0; . + $item)'2331 input: '[10,2,5,3]'2332 output: ['20']23332347 - title: "`limit(n; exp)`"2348 body: |23492350 The `limit` function extracts up to `n` outputs from `exp`.
31 unmodified lines
2382 - program: '[range(.)]|[first, last, nth(5)]'2383 input: '10'2384 output: ['[0,9,5]']23852386 - title: "`reduce`"2387 body: |23882389 The `reduce` syntax allows you to combine all of the results of2390 an expression by accumulating them into a single answer.2391 The form is `reduce EXP as $var (INIT; UPDATE)`.2392 As an example, we'll pass `[1,2,3]` to this expression:23932394 reduce .[] as $item (0; . + $item)23952396 For each result that `.[]` produces, `. + $item` is run to2397 accumulate a running total, starting from 0 as the input value.2398 In this example, `.[]` produces the results `1`, `2`, and `3`,2399 so the effect is similar to running something like this:24002401 0 | 1 as $item | . + $item |2402 2 as $item | . + $item |2403 3 as $item | . + $item24042405 examples:2406 - program: 'reduce .[] as $item (0; . + $item)'2407 input: '[1,2,3,4,5]'2408 output: ['15']24092410 - program: 'reduce .[] as [$i,$j] (0; . + $i * $j)'2411 input: '[[1,2],[3,4],[5,6]]'2412 output: ['44']24132414 - program: 'reduce .[] as {$x,$y} (null; .x += $x | .y += [$y])'2415 input: '[{"x":"a","y":1},{"x":"b","y":2},{"x":"c","y":3}]'2416 output: ['{"x":"abc","y":[1,2,3]}']24172418 - title: "`foreach`"2419 body: |24202421 The `foreach` syntax is similar to `reduce`, but intended to2422 allow the construction of `limit` and reducers that produce2378 intermediate results (see example).2423 intermediate results.24242425 The form is `foreach EXP as $var (INIT; UPDATE; EXTRACT)`.2381 Like `reduce`, `INIT` is evaluated once to produce a state2382 value, then each output of `EXP` is bound to `$var`, `UPDATE`2383 is evaluated for each output of `EXP` with the current state2384 and with `$var` visible. Each value output by `UPDATE`2385 replaces the previous state. Finally, `EXTRACT` is evaluated2386 for each new state to extract an output of `foreach`.2426 As an example, we'll pass `[1,2,3]` to this expression:24272388 This is mostly useful only for constructing `reduce`- and2389 `limit`-like functions. But it is much more general, as it2390 allows for partial reductions (see the example below).2428 foreach .[] as $item (0; . + $item; [$item, . * 2])24292430 Like the `reduce` syntax, `. + $item` is run for each result2431 that `.[]` produces, but `[$item, . * 2]` is run for each2432 intermediate values. In this example, since the intermediate2433 values are `1`, `3`, and `6`, the `foreach` expression produces2434 `[1,2]`, `[2,6]`, and `[3,12]`. So the effect is similar2435 to running something like this:24362437 0 | 1 as $item | . + $item | [$item, . * 2],2438 2 as $item | . + $item | [$item, . * 2],2439 3 as $item | . + $item | [$item, . * 2]24402441 When `EXTRACT` is omitted, the identity filter is used.2442 That is, it outputs the intermediate values as they are.24432444 examples:2393 - program: '[foreach .[] as $item2394 ([[],[]];2395 if $item == null then [[],.[0]] else [(.[0] + [$item]),[]] end;2396 if $item == null then .[1] else empty end)]'2397 input: '[1,2,3,4,null,"a","b",null]'2398 output: ['[[1,2,3,4],["a","b"]]']2445 - program: 'foreach .[] as $item (0; . + $item)'2446 input: '[1,2,3,4,5]'2447 output: ['1','3','6','10','15']24482449 - program: 'foreach .[] as $item (0; . + $item; [$item, . * 2])'2450 input: '[1,2,3,4,5]'2451 output: ['[1,2]','[2,6]','[3,12]','[4,20]','[5,30]']24522453 - program: 'foreach .[] as $item (0; . + 1; {index: ., $item})'2454 input: '["foo", "bar", "baz"]'2455 output:2456 - '{"index":1,"item":"foo"}'2457 - '{"index":2,"item":"bar"}'2458 - '{"index":3,"item":"baz"}'24592460 - title: Recursion2461 body: |24622463 As described above, `recurse` uses recursion, and any jq
106 unmodified lines
2570 body: |25712572 Outputs one new input.25732574 echo 1 2 3 4 | jq '[., input]' # [1,2] [3,4]25752576 - title: "`inputs`"2577 body: |25782579 Outputs all remaining inputs, one by one.25802581 This is primarily useful for reductions over a program's2582 inputs.25832584 echo 1 2 3 | jq -n 'reduce inputs as $i (0; . + $i)' # 625852586 - title: "`debug`"2587 body: |25882589 Causes a debug message based on the input value to be
44 unmodified lines
2634 number of path elements from the left of the outputs of the2635 given streaming expression.26362637 examples:2574 - program: '[1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])]'2638 - program: 'truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])'2639 input: '1'2576 output: ['[[[0],2],[[0]]]']2640 output: ['[[0],2]', '[[0]]']26412642 - title: "`fromstream(stream_expression)`"2643 body: |2644
286 unmodified lines
modified:docs/content/manual/v1.6/manual.yml+135 added-61 removed
76 unmodified lines
7778 jq filters run on a stream of JSON data. The input to jq is79 parsed as a sequence of whitespace-separated JSON values which80 are passed through the provided filter one at a time. The81 output(s) of the filter are written to standard out, again as a82 sequence of whitespace-separated JSON data.81 output(s) of the filter are written to standard output, as a82 sequence of newline-separated JSON data.8384 Note: it is important to mind the shell's quoting rules. As a85 general rule it's best to always quote (with single-quote86 characters) the jq program, as too many characters with special
309 unmodified lines
396 elements from index 10 (inclusive) to index 15 (exclusive).397 Either index may be negative (in which case it counts398 backwards from the end of the array), or omitted (in which399 case it refers to the start or end of the array).400 Indices are zero-based.401402 examples:403 - program: '.[2:4]'404 input: '["a","b","c","d","e"]'
17 unmodified lines
422 If you use the `.[index]` syntax, but omit the index423 entirely, it will return *all* of the elements of an424 array. Running `.[]` with the input `[1,2,3]` will produce the425 numbers as three separate results, rather than as a single425 array.426 array. A filter of the form `.foo[]` is equivalent to427 `.foo | .[]`.428429 You can also use this on an object, and it will return all430 the values of the object.431
7 unmodified lines
439 - program: '.[]'440 input: '[]'441 output: []442443 - program: '.foo[]'444 input: '{"foo":[1,2,3]}'445 output: ['1','2','3']446447 - program: '.[]'448 input: '{"a": 1, "b": 1}'449 output: ['1', '1']450451 - title: "`.[]?`"452 body: |453454 Like `.[]`, but no errors will be output if . is not an array449 or object.455 or object. A filter of the form `.foo[]?` is equivalent to456 `.foo | .[]?`.457458 - title: "Comma: `,`"459 body: |460
61 unmodified lines
522 strings, booleans, arrays, objects (which in JSON-speak are523 hashes with only string keys), and "null".524525 Booleans, null, strings and numbers are written the same way as519 in javascript. Just like everything else in jq, these simple526 in JSON. Just like everything else in jq, these simple527 values take an input and produce an output - `42` is a valid jq528 expression that takes an input, ignores it, and returns 42529 instead.530
93 unmodified lines
624625 Recursively descends `.`, producing every value. This is the626 same as the zero-argument `recurse` builtin (see below). This627 is intended to resemble the XPath `//` operator. Note that621 `..a` does not work; use `..|.a` instead. In the example622 below we use `..|.a?` to find all the values of object keys628 `..a` does not work; use `.. | .a` instead. In the example629 below we use `.. | .a?` to find all the values of object keys630 "a" in any object found "below" `.`.631632 This is particularly useful in conjunction with `path(EXP)`633 (also see below) and the `?` operator.634635 examples:629 - program: '..|.a?'636 - program: '.. | .a?'637 input: '[[{"a":1}]]'638 output: ['1']639640 - title: Builtin operators and functions
373 unmodified lines
1014 - program: '[1,2,empty,3]'1015 input: 'null'1016 output: ['[1,2,3]']10171011 - title: "`error(message)`"1018 - title: "`error`, `error(message)`"1019 body: |10201014 Produces an error, just like `.a` applied to values other than1015 null and objects would, but with the given message as the1016 error's value. Errors can be caught with try/catch; see below.1021 Produces an error with the input value, or with the message1022 given as the argument. Errors can be caught with try/catch;1023 see below.10241025 When the error value is `null`, it produces nothing and works1026 just like `empty`. So `[null | error]` and `[error(null)]` both1027 emit `[]`.10281029 examples:1030 - program: 'try error catch .'1031 input: '"error message"'1032 output: ['"error message"']10331034 - program: 'try error("invalid value: \(.)") catch .'1035 input: '42'1036 output: ['"invalid value: 42"']10371038 - title: "`halt`"1039 body: |10401041 Stops the jq program with no further outputs. jq will exit
279 unmodified lines
1321 compared by comparing their sets of keys (as arrays in1322 sorted order), and if their keys are equal then the values1323 are compared key by key.13241305 `sort` may be used to sort by a particular field of an1306 object, or by applying any jq filter.1325 `sort_by` may be used to sort by a particular field of an1326 object, or by applying any jq filter. `sort_by(f)` compares1327 two elements by comparing the result of `f` on each element.1328 When `f` produces multiple values, it firstly compares the1329 first values, and the second values if the first values are1330 equal, and so on.13311308 `sort_by(f)` compares two elements by comparing the result of1309 `f` on each element.13101332 examples:1333 - program: 'sort'1334 input: '[8,3,null,6]'1335 output: ['[null,3,6,8]']13361337 - program: 'sort_by(.foo)'1316 input: '[{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]'1317 output: ['[{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]']1338 input: '[{"foo":4, "bar":10}, {"foo":3, "bar":10}, {"foo":2, "bar":1}]'1339 output: ['[{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":4, "bar":10}]']13401341 - program: 'sort_by(.foo, .bar)'1342 input: '[{"foo":4, "bar":10}, {"foo":3, "bar":20}, {"foo":2, "bar":1}, {"foo":3, "bar":10}]'1343 output: ['[{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":3, "bar":20}, {"foo":4, "bar":10}]']13441345 - title: "`group_by(path_expression)`"1346 body: |13471348 `group_by(.foo)` takes as input an array, groups the
117 unmodified lines
1466 examples:1467 - program: 'index(", ")'1468 input: '"a,b, cd, efg, hijk"'1469 output: ['3']1470 - program: 'index(1)'1471 input: '[0,1,2,1,3,1,4]'1472 output: ['1']1473 - program: 'index([1,2])'1474 input: '[0,1,2,3,1,4,2,5,1,2,6,7]'1475 output: ['1']1476 - program: 'rindex(", ")'1477 input: '"a,b, cd, efg, hijk"'1478 output: ['12']1479 - program: 'rindex(1)'1480 input: '[0,1,2,1,3,1,4]'1481 output: ['5']1482 - program: 'rindex([1,2])'1483 input: '[0,1,2,3,1,4,2,5,1,2,6,7]'1484 output: ['8']14851486 - title: "`inside`"1487 body: |1488
196 unmodified lines
16851686 When called without an argument, `recurse` is equivalent to1687 `recurse(.[]?)`.16881651 `recurse(f)` is identical to `recurse(f; . != null)` and can be1689 `recurse(f)` is identical to `recurse(f; true)` and can be1690 used without concerns about recursion depth.16911692 `recurse(f; condition)` is a generator which begins by1693 emitting . and then emits in turn .|f, .|f|f, .|f|f|f, ... so long
977 unmodified lines
2671 left". Consider this expression now, `... | (.*3 as2672 $times_three | [. + $times_three]) | ...`: here the binding2673 `$times_three` is _not_ visible past the closing parenthesis.26742637 - title: Reduce2638 body: |26392640 The `reduce` syntax in jq allows you to combine all of the2641 results of an expression by accumulating them into a single2642 answer. As an example, we'll pass `[3,2,1]` to this expression:26432644 reduce .[] as $item (0; . + $item)26452646 For each result that `.[]` produces, `. + $item` is run to2647 accumulate a running total, starting from 0. In this2648 example, `.[]` produces the results 3, 2, and 1, so the2649 effect is similar to running something like this:26502651 0 | (3 as $item | . + $item) |2652 (2 as $item | . + $item) |2653 (1 as $item | . + $item)26542655 examples:2656 - program: 'reduce .[] as $item (0; . + $item)'2657 input: '[10,2,5,3]'2658 output: ['20']26592675 - title: "`isempty(exp)`"2676 body: |26772678 Returns true if `exp` produces no outputs, false otherwise.
2 unmodified lines
2681 - program: 'isempty(empty)'2682 input: 'null'2683 output: ['true']26842685 - program: 'isempty(.[])'2686 input: '[]'2687 output: ['true']26882689 - program: 'isempty(.[])'2690 input: '[1,2,3]'2691 output: ['false']26922693 - title: "`limit(n; exp)`"2694 body: |26952696 The `limit` function extracts up to `n` outputs from `exp`.
31 unmodified lines
2728 - program: '[range(.)]|[first, last, nth(5)]'2729 input: '10'2730 output: ['[0,9,5]']27312732 - title: "`reduce`"2733 body: |27342735 The `reduce` syntax allows you to combine all of the results of2736 an expression by accumulating them into a single answer.2737 The form is `reduce EXP as $var (INIT; UPDATE)`.2738 As an example, we'll pass `[1,2,3]` to this expression:27392740 reduce .[] as $item (0; . + $item)27412742 For each result that `.[]` produces, `. + $item` is run to2743 accumulate a running total, starting from 0 as the input value.2744 In this example, `.[]` produces the results `1`, `2`, and `3`,2745 so the effect is similar to running something like this:27462747 0 | 1 as $item | . + $item |2748 2 as $item | . + $item |2749 3 as $item | . + $item27502751 examples:2752 - program: 'reduce .[] as $item (0; . + $item)'2753 input: '[1,2,3,4,5]'2754 output: ['15']27552756 - program: 'reduce .[] as [$i,$j] (0; . + $i * $j)'2757 input: '[[1,2],[3,4],[5,6]]'2758 output: ['44']27592760 - program: 'reduce .[] as {$x,$y} (null; .x += $x | .y += [$y])'2761 input: '[{"x":"a","y":1},{"x":"b","y":2},{"x":"c","y":3}]'2762 output: ['{"x":"abc","y":[1,2,3]}']27632764 - title: "`foreach`"2765 body: |27662767 The `foreach` syntax is similar to `reduce`, but intended to2768 allow the construction of `limit` and reducers that produce2714 intermediate results (see example).2769 intermediate results.27702771 The form is `foreach EXP as $var (INIT; UPDATE; EXTRACT)`.2717 Like `reduce`, `INIT` is evaluated once to produce a state2718 value, then each output of `EXP` is bound to `$var`, `UPDATE`2719 is evaluated for each output of `EXP` with the current state2720 and with `$var` visible. Each value output by `UPDATE`2721 replaces the previous state. Finally, `EXTRACT` is evaluated2722 for each new state to extract an output of `foreach`.2772 As an example, we'll pass `[1,2,3]` to this expression:27732724 This is mostly useful only for constructing `reduce`- and2725 `limit`-like functions. But it is much more general, as it2726 allows for partial reductions (see the example below).2774 foreach .[] as $item (0; . + $item; [$item, . * 2])27752776 Like the `reduce` syntax, `. + $item` is run for each result2777 that `.[]` produces, but `[$item, . * 2]` is run for each2778 intermediate values. In this example, since the intermediate2779 values are `1`, `3`, and `6`, the `foreach` expression produces2780 `[1,2]`, `[2,6]`, and `[3,12]`. So the effect is similar2781 to running something like this:27822783 0 | 1 as $item | . + $item | [$item, . * 2],2784 2 as $item | . + $item | [$item, . * 2],2785 3 as $item | . + $item | [$item, . * 2]27862787 When `EXTRACT` is omitted, the identity filter is used.2788 That is, it outputs the intermediate values as they are.27892790 examples:2729 - program: '[foreach .[] as $item2730 ([[],[]];2731 if $item == null then [[],.[0]] else [(.[0] + [$item]),[]] end;2732 if $item == null then .[1] else empty end)]'2733 input: '[1,2,3,4,null,"a","b",null]'2734 output: ['[[1,2,3,4],["a","b"]]']2791 - program: 'foreach .[] as $item (0; . + $item)'2792 input: '[1,2,3,4,5]'2793 output: ['1','3','6','10','15']27942795 - program: 'foreach .[] as $item (0; . + $item; [$item, . * 2])'2796 input: '[1,2,3,4,5]'2797 output: ['[1,2]','[2,6]','[3,12]','[4,20]','[5,30]']27982799 - program: 'foreach .[] as $item (0; . + 1; {index: ., $item})'2800 input: '["foo", "bar", "baz"]'2801 output:2802 - '{"index":1,"item":"foo"}'2803 - '{"index":2,"item":"bar"}'2804 - '{"index":3,"item":"baz"}'28052806 - title: Recursion2807 body: |28082809 As described above, `recurse` uses recursion, and any jq
129 unmodified lines
2939 body: |29402941 Outputs one new input.29422943 echo 1 2 3 4 | jq '[., input]' # [1,2] [3,4]29442945 - title: "`inputs`"2946 body: |29472948 Outputs all remaining inputs, one by one.29492950 This is primarily useful for reductions over a program's2951 inputs.29522953 echo 1 2 3 | jq -n 'reduce inputs as $i (0; . + $i)' # 629542955 - title: "`debug`"2956 body: |29572958 Causes a debug message based on the input value to be
50 unmodified lines
3009 number of path elements from the left of the outputs of the3010 given streaming expression.30113012 examples:2939 - program: '[1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])]'3013 - program: 'truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])'3014 input: '1'2941 output: ['[[[0],2],[[0]]]']3015 output: ['[[0],2]', '[[0]]']30163017 - title: "`fromstream(stream_expression)`"3018 body: |3019
345 unmodified lines
modified:docs/content/manual/manual.yml+140 added-66 removed
77 unmodified lines
7879 jq filters run on a stream of JSON data. The input to jq is80 parsed as a sequence of whitespace-separated JSON values which81 are passed through the provided filter one at a time. The82 output(s) of the filter are written to standard out, again as a83 sequence of whitespace-separated JSON data.82 output(s) of the filter are written to standard output, as a83 sequence of newline-separated JSON data.8485 Note: it is important to mind the shell's quoting rules. As a86 general rule it's best to always quote (with single-quote87 characters) the jq program, as too many characters with special
43 unmodified lines
131 to reduce large inputs incrementally.132133 * `--stream-errors`:134135 Like `--stream`, but invalid JSON inputs yield array calues135 Like `--stream`, but invalid JSON inputs yield array values136 where the first element is the error and the second is a path.137 For example, `["a",n]` produces ["Invalid literal at line 1,138 column 9",[1]]`.139
193 unmodified lines
333 Although the identity filter never modifies the value of its334 input, jq processing can sometimes make it appear as though335 it does. For example, using the current implementation of336 jq, we would see that the expression:337 337338 1E1234567890 | .339340 produces `1.7976931348623157e+308` on at least one platform.341 This is because, in the process of parsing the number, this
29 unmodified lines
371 input: '"Hello, world!"'372 output: ['"Hello, world!"']373374 - program: '.'375 input: '0.12345678901234567890123456789'375 input: '0.12345678901234567890123456789'376 output: ['0.12345678901234567890123456789']377378 - program: '[., tojson]'379 input: '12345678909876543212345'
17 unmodified lines
397 The simplest *useful* filter has the form `.foo`. When given a398 JSON object (aka dictionary or hash) as input, `.foo` produces399 the value at the key "foo" if the key is present, or null otherwise.400401 A filter of the form `.foo.bar` is equivalent to `.foo|.bar`.401 A filter of the form `.foo.bar` is equivalent to `.foo | .bar`.402403 The `.foo` syntax only works for simple, identifier-like keys, that404 is, keys that are all made of alphanumeric characters and405 underscore, and which do not start with a digit.
77 unmodified lines
483 elements from index 10 (inclusive) to index 15 (exclusive).484 Either index may be negative (in which case it counts485 backwards from the end of the array), or omitted (in which486 case it refers to the start or end of the array).487 Indices are zero-based.488489 examples:490 - program: '.[2:4]'491 input: '["a","b","c","d","e"]'
17 unmodified lines
509 If you use the `.[index]` syntax, but omit the index510 entirely, it will return *all* of the elements of an511 array. Running `.[]` with the input `[1,2,3]` will produce the512 numbers as three separate results, rather than as a single512 array.513 array. A filter of the form `.foo[]` is equivalent to514 `.foo | .[]`.515516 You can also use this on an object, and it will return all517 the values of the object.518
7 unmodified lines
526 - program: '.[]'527 input: '[]'528 output: []529530 - program: '.foo[]'531 input: '{"foo":[1,2,3]}'532 output: ['1','2','3']533534 - program: '.[]'535 input: '{"a": 1, "b": 1}'536 output: ['1', '1']537538 - title: "`.[]?`"539 body: |540541 Like `.[]`, but no errors will be output if . is not an array536 or object.542 or object. A filter of the form `.foo[]?` is equivalent to543 `.foo | .[]?`.544545 - title: "Comma: `,`"546 body: |547
186 unmodified lines
734735 Recursively descends `.`, producing every value. This is the736 same as the zero-argument `recurse` builtin (see below). This737 is intended to resemble the XPath `//` operator. Note that731 `..a` does not work; use `..|.a` instead. In the example732 below we use `..|.a?` to find all the values of object keys738 `..a` does not work; use `.. | .a` instead. In the example739 below we use `.. | .a?` to find all the values of object keys740 "a" in any object found "below" `.`.741742 This is particularly useful in conjunction with `path(EXP)`743 (also see below) and the `?` operator.744745 examples:739 - program: '..|.a?'746 - program: '.. | .a?'747 input: '[[{"a":1}]]'748 output: ['1']749750 - title: Builtin operators and functions
445 unmodified lines
1196 - program: '[1,2,empty,3]'1197 input: 'null'1198 output: ['[1,2,3]']11991193 - title: "`error(message)`"1200 - title: "`error`, `error(message)`"1201 body: |12021196 Produces an error, just like `.a` applied to values other than1197 null and objects would, but with the given message as the1198 error's value. Errors can be caught with try/catch; see below.1203 Produces an error with the input value, or with the message1204 given as the argument. Errors can be caught with try/catch;1205 see below.12061207 When the error value is `null`, it produces nothing and works1208 just like `empty`. So `[null | error]` and `[error(null)]` both1209 emit `[]`.12101211 examples:1212 - program: 'try error catch .'1213 input: '"error message"'1214 output: ['"error message"']12151216 - program: 'try error("invalid value: \(.)") catch .'1217 input: '42'1218 output: ['"invalid value: 42"']12191220 - title: "`halt`"1221 body: |12221223 Stops the jq program with no further outputs. jq will exit
276 unmodified lines
1500 compared by comparing their sets of keys (as arrays in1501 sorted order), and if their keys are equal then the values1502 are compared key by key.15031484 `sort` may be used to sort by a particular field of an1485 object, or by applying any jq filter.1504 `sort_by` may be used to sort by a particular field of an1505 object, or by applying any jq filter. `sort_by(f)` compares1506 two elements by comparing the result of `f` on each element.1507 When `f` produces multiple values, it firstly compares the1508 first values, and the second values if the first values are1509 equal, and so on.15101487 `sort_by(f)` compares two elements by comparing the result of1488 `f` on each element.14891511 examples:1512 - program: 'sort'1513 input: '[8,3,null,6]'1514 output: ['[null,3,6,8]']15151516 - program: 'sort_by(.foo)'1495 input: '[{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]'1496 output: ['[{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]']1517 input: '[{"foo":4, "bar":10}, {"foo":3, "bar":10}, {"foo":2, "bar":1}]'1518 output: ['[{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":4, "bar":10}]']15191520 - program: 'sort_by(.foo, .bar)'1521 input: '[{"foo":4, "bar":10}, {"foo":3, "bar":20}, {"foo":2, "bar":1}, {"foo":3, "bar":10}]'1522 output: ['[{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":3, "bar":20}, {"foo":4, "bar":10}]']15231524 - title: "`group_by(path_expression)`"1525 body: |15261527 `group_by(.foo)` takes as input an array, groups the
117 unmodified lines
1645 examples:1646 - program: 'index(", ")'1647 input: '"a,b, cd, efg, hijk"'1648 output: ['3']1649 - program: 'index(1)'1650 input: '[0,1,2,1,3,1,4]'1651 output: ['1']1652 - program: 'index([1,2])'1653 input: '[0,1,2,3,1,4,2,5,1,2,6,7]'1654 output: ['1']1655 - program: 'rindex(", ")'1656 input: '"a,b, cd, efg, hijk"'1657 output: ['12']1658 - program: 'rindex(1)'1659 input: '[0,1,2,1,3,1,4]'1660 output: ['5']1661 - program: 'rindex([1,2])'1662 input: '[0,1,2,3,1,4,2,5,1,2,6,7]'1663 output: ['8']16641665 - title: "`inside`"1666 body: |1667
215 unmodified lines
18831884 When called without an argument, `recurse` is equivalent to1885 `recurse(.[]?)`.18861849 `recurse(f)` is identical to `recurse(f; . != null)` and can be1887 `recurse(f)` is identical to `recurse(f; true)` and can be1888 used without concerns about recursion depth.18891890 `recurse(f; condition)` is a generator which begins by1891 emitting . and then emits in turn .|f, .|f|f, .|f|f|f, ... so long
1006 unmodified lines
2898 left". Consider this expression now, `... | (.*3 as2899 $times_three | [. + $times_three]) | ...`: here the binding2900 `$times_three` is _not_ visible past the closing parenthesis.29012864 - title: Reduce2865 body: |28662867 The `reduce` syntax in jq allows you to combine all of the2868 results of an expression by accumulating them into a single2869 answer. As an example, we'll pass `[3,2,1]` to this expression:28702871 reduce .[] as $item (0; . + $item)28722873 For each result that `.[]` produces, `. + $item` is run to2874 accumulate a running total, starting from 0. In this2875 example, `.[]` produces the results 3, 2, and 1, so the2876 effect is similar to running something like this:28772878 0 | (3 as $item | . + $item) |2879 (2 as $item | . + $item) |2880 (1 as $item | . + $item)28812882 examples:2883 - program: 'reduce .[] as $item (0; . + $item)'2884 input: '[10,2,5,3]'2885 output: ['20']28862902 - title: "`isempty(exp)`"2903 body: |29042905 Returns true if `exp` produces no outputs, false otherwise.
2 unmodified lines
2908 - program: 'isempty(empty)'2909 input: 'null'2910 output: ['true']29112912 - program: 'isempty(.[])'2913 input: '[]'2914 output: ['true']29152916 - program: 'isempty(.[])'2917 input: '[1,2,3]'2918 output: ['false']29192920 - title: "`limit(n; exp)`"2921 body: |29222923 The `limit` function extracts up to `n` outputs from `exp`.
29 unmodified lines
2953 - program: '[range(.)]|[first, last, nth(5)]'2954 input: '10'2955 output: ['[0,9,5]']29562957 - title: "`reduce`"2958 body: |29592960 The `reduce` syntax allows you to combine all of the results of2961 an expression by accumulating them into a single answer.2962 The form is `reduce EXP as $var (INIT; UPDATE)`.2963 As an example, we'll pass `[1,2,3]` to this expression:29642965 reduce .[] as $item (0; . + $item)29662967 For each result that `.[]` produces, `. + $item` is run to2968 accumulate a running total, starting from 0 as the input value.2969 In this example, `.[]` produces the results `1`, `2`, and `3`,2970 so the effect is similar to running something like this:29712972 0 | 1 as $item | . + $item |2973 2 as $item | . + $item |2974 3 as $item | . + $item29752976 examples:2977 - program: 'reduce .[] as $item (0; . + $item)'2978 input: '[1,2,3,4,5]'2979 output: ['15']29802981 - program: 'reduce .[] as [$i,$j] (0; . + $i * $j)'2982 input: '[[1,2],[3,4],[5,6]]'2983 output: ['44']29842985 - program: 'reduce .[] as {$x,$y} (null; .x += $x | .y += [$y])'2986 input: '[{"x":"a","y":1},{"x":"b","y":2},{"x":"c","y":3}]'2987 output: ['{"x":"abc","y":[1,2,3]}']29882989 - title: "`foreach`"2990 body: |29912992 The `foreach` syntax is similar to `reduce`, but intended to2993 allow the construction of `limit` and reducers that produce2939 intermediate results (see example).2994 intermediate results.29952996 The form is `foreach EXP as $var (INIT; UPDATE; EXTRACT)`.2942 Like `reduce`, `INIT` is evaluated once to produce a state2943 value, then each output of `EXP` is bound to `$var`, `UPDATE`2944 is evaluated for each output of `EXP` with the current state2945 and with `$var` visible. Each value output by `UPDATE`2946 replaces the previous state. Finally, `EXTRACT` is evaluated2947 for each new state to extract an output of `foreach`.2997 As an example, we'll pass `[1,2,3]` to this expression:29982949 This is mostly useful only for constructing `reduce`- and2950 `limit`-like functions. But it is much more general, as it2951 allows for partial reductions (see the example below).2999 foreach .[] as $item (0; . + $item; [$item, . * 2])30003001 Like the `reduce` syntax, `. + $item` is run for each result3002 that `.[]` produces, but `[$item, . * 2]` is run for each3003 intermediate values. In this example, since the intermediate3004 values are `1`, `3`, and `6`, the `foreach` expression produces3005 `[1,2]`, `[2,6]`, and `[3,12]`. So the effect is similar3006 to running something like this:30073008 0 | 1 as $item | . + $item | [$item, . * 2],3009 2 as $item | . + $item | [$item, . * 2],3010 3 as $item | . + $item | [$item, . * 2]30113012 When `EXTRACT` is omitted, the identity filter is used.3013 That is, it outputs the intermediate values as they are.30143015 examples:2954 - program: '[foreach .[] as $item2955 ([[],[]];2956 if $item == null then [[],.[0]] else [(.[0] + [$item]),[]] end;2957 if $item == null then .[1] else empty end)]'2958 input: '[1,2,3,4,null,"a","b",null]'2959 output: ['[[1,2,3,4],["a","b"]]']3016 - program: 'foreach .[] as $item (0; . + $item)'3017 input: '[1,2,3,4,5]'3018 output: ['1','3','6','10','15']30193020 - program: 'foreach .[] as $item (0; . + $item; [$item, . * 2])'3021 input: '[1,2,3,4,5]'3022 output: ['[1,2]','[2,6]','[3,12]','[4,20]','[5,30]']30233024 - program: 'foreach .[] as $item (0; . + 1; {index: ., $item})'3025 input: '["foo", "bar", "baz"]'3026 output:3027 - '{"index":1,"item":"foo"}'3028 - '{"index":2,"item":"bar"}'3029 - '{"index":3,"item":"baz"}'30303031 - title: Recursion3032 body: |30333034 As described above, `recurse` uses recursion, and any jq
132 unmodified lines
31673168 Outputs one new input.31693170 Note that when using `input` it is generally be necessary to3101 invoke jq with the -n command-line option, otherwise3171 invoke jq with the `-n` command-line option, otherwise3172 the first entity will be lost.31733174 echo 1 2 3 4 | jq '[., input]' # [1,2] [3,4]31753176 - title: "`inputs`"3177 body: |31783179 Outputs all remaining inputs, one by one.31803181 This is primarily useful for reductions over a program's3182 inputs. Note that when using `inputs` it is generally necessary3111 to invoke jq with the -n command-line option, otherwise3183 to invoke jq with the `-n` command-line option, otherwise3184 the first entity will be lost.31853186 echo 1 2 3 | jq -n 'reduce inputs as $i (0; . + $i)' # 631873188 - title: "`debug`, `debug(msgs)`"3189 body: |31903191 These two filters are like `.` but have as a side-effect the
69 unmodified lines
3261 number of path elements from the left of the outputs of the3262 given streaming expression.32633264 examples:3191 - program: '[1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])]'3265 - program: 'truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])'3266 input: '1'3193 output: ['[[[0],2],[[0]]]']3267 output: ['[[0],2]', '[[0]]']32683269 - title: "`fromstream(stream_expression)`"3270 body: |3271
357 unmodified lines
modified:tests/jq.test+8 added
1230 unmodified lines
1231[[.[]|[.a,.a]]?]1232[null,true,{"a":1}]1233[]12341235[1,error,2]1236null1237[1,2]12381239[1,error(null),2]124001241[1,2]12421243try error("\($__loc__)") catch .1244null1245"{\"file\":\"<top-level>\",\"line\":1}"1246
653 unmodified lines
modified:tests/man.test+81 added-12 removed
84 unmodified lines
8586.[]87[]8889.foo[]90{"foo":[1,2,3]}9119229339495.[]96{"a": 1, "b": 1}971981
39 unmodified lines
138{(.user): .titles}139{"user":"stedolan","titles":["JQ Primer", "More JQ"]}140{"stedolan": ["JQ Primer", "More JQ"]}141136..|.a?142.. | .a?143[[{"a":1}]]1441145146.a + 1
174 unmodified lines
321[1,2,empty,3]322null323[1,2,3]324325try error catch .326"error message"327"error message"328329try error("invalid value: \(.)") catch .33042331"invalid value: 42"332333try error("\($__loc__)") catch .334null335"{\"file\":\"<top-level>\",\"line\":1}"336
119 unmodified lines
456[8,3,null,6]457[null,3,6,8]458459sort_by(.foo)446[{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]447[{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]460[{"foo":4, "bar":10}, {"foo":3, "bar":10}, {"foo":2, "bar":1}]461[{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":4, "bar":10}]462463sort_by(.foo, .bar)464[{"foo":4, "bar":10}, {"foo":3, "bar":20}, {"foo":2, "bar":1}, {"foo":3, "bar":10}]465[{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":3, "bar":20}, {"foo":4, "bar":10}]466467group_by(.foo)468[{"foo":1, "bar":10}, {"foo":3, "bar":100}, {"foo":1, "bar":1}]469[[{"foo":1, "bar":10}, {"foo":1, "bar":1}], [{"foo":3, "bar":100}]]470
56 unmodified lines
527index(", ")528"a,b, cd, efg, hijk"5293530531index(1)532[0,1,2,1,3,1,4]5331534535index([1,2])536[0,1,2,3,1,4,2,5,1,2,6,7]5371538539rindex(", ")540"a,b, cd, efg, hijk"54112542543rindex(1)544[0,1,2,1,3,1,4]5455546547rindex([1,2])548[0,1,2,3,1,4,2,5,1,2,6,7]5498550551inside("foobar")552"bar"553true554
277 unmodified lines
832def addvalue(f): f as $x | map(. + $x); addvalue(.[0])833[[1,2],[10,20]]834[[1,2,1,2], [10,20,1,2]]835802reduce .[] as $item (0; . + $item)803[10,2,5,3]80420805836isempty(empty)837null838true839840isempty(.[])841[]842true843844isempty(.[])845[1,2,3]846false847848[limit(3;.[])]849[0,1,2,3,4,5,6,7,8,9]850[0,1,2]851
4 unmodified lines
856[range(.)]|[first, last, nth(5)]85710858[0,9,5]859822[foreach .[] as $item ([[],[]]; if $item == null then [[],.[0]] else [(.[0] + [$item]),[]] end; if $item == null then .[1] else empty end)]823[1,2,3,4,null,"a","b",null]824[[1,2,3,4],["a","b"]]860reduce .[] as $item (0; . + $item)861[1,2,3,4,5]86215863864reduce .[] as [$i,$j] (0; . + $i * $j)865[[1,2],[3,4],[5,6]]86644867868reduce .[] as {$x,$y} (null; .x += $x | .y += [$y])869[{"x":"a","y":1},{"x":"b","y":2},{"x":"c","y":3}]870{"x":"abc","y":[1,2,3]}871872foreach .[] as $item (0; . + $item)873[1,2,3,4,5]8741875387668771087815879880foreach .[] as $item (0; . + $item; [$item, . * 2])881[1,2,3,4,5]882[1,2]883[2,6]884[3,12]885[4,20]886[5,30]887888foreach .[] as $item (0; . + 1; {index: ., $item})889["foo", "bar", "baz"]890{"index":1,"item":"foo"}891{"index":2,"item":"bar"}892{"index":3,"item":"baz"}893894def range(init; upto; by): def _range: if (by > 0 and . < upto) or (by < 0 and . > upto) then ., ((.+by)|_range) else . end; if by == 0 then init else init|_range end | select((by > 0 and . < upto) or (by < 0 and . > upto)); range(0; 10; 3)895null89608973
3 unmodified lines
901def while(cond; update): def _while: if cond then ., (update | _while) else empty end; _while; [while(.<100; .*2)]9021903[1,2,4,8,16,32,64]904837[1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])]905truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])9061839[[[0],2],[[0]]]907[[0],2]908[[0]]909910fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))911null912[2]
31 unmodified lines
modified:jq.1.prebuilt+168 added-59 removed
30 unmodified lines
31.P32But that\'s getting ahead of ourselves\. :) Let\'s start with something simpler:33.34.SH "INVOKING JQ"35jq filters run on a stream of JSON data\. The input to jq is parsed as a sequence of whitespace\-separated JSON values which are passed through the provided filter one at a time\. The output(s) of the filter are written to standard out, again as a sequence of whitespace\-separated JSON data\.35jq filters run on a stream of JSON data\. The input to jq is parsed as a sequence of whitespace\-separated JSON values which are passed through the provided filter one at a time\. The output(s) of the filter are written to standard output, as a sequence of newline\-separated JSON data\.36.37.P38Note: it is important to mind the shell\'s quoting rules\. As a general rule it\'s best to always quote (with single\-quote characters) the jq program, as too many characters with special meaning to jq are also shell meta\-characters\. For example, \fBjq "foo"\fR will fail on most Unix shells because that will be the same as \fBjq foo\fR, which will generally fail because \fBfoo is not defined\fR\. When using the Windows command shell (cmd\.exe) it\'s best to use double quotes around your jq program when given on the command\-line (instead of the \fB\-f program\-file\fR option), but then double\-quotes in the jq program need backslash escaping\. When using the Powershell (\fBpowershell\.exe\fR) or the Powershell Core (\fBpwsh\fR/\fBpwsh\.exe\fR), use single\-quote characters around the jq program and backslash\-escaped double\-quotes (\fB\e"\fR) inside the jq program\.39.
35 unmodified lines
75.TP76\fB\-\-stream\-errors\fR:77.78.IP79Like \fB\-\-stream\fR, but invalid JSON inputs yield array calues where the first element is the error and the second is a path\. For example, \fB["a",n]\fR produces ["Invalid literal at line 1, column 9",[1]]`\.79Like \fB\-\-stream\fR, but invalid JSON inputs yield array values where the first element is the error and the second is a path\. For example, \fB["a",n]\fR produces ["Invalid literal at line 1, column 9",[1]]`\.80.81.IP82Implies \fB\-\-stream\fR\. Invalid JSON inputs produce no error values when \fB\-\-stream\fR without \fB\-\-stream\-errors\fR\.83.
242 unmodified lines
326.SS "Object Identifier\-Index: \.foo, \.foo\.bar"327The simplest \fIuseful\fR filter has the form \fB\.foo\fR\. When given a JSON object (aka dictionary or hash) as input, \fB\.foo\fR produces the value at the key "foo" if the key is present, or null otherwise\.328.329.P330A filter of the form \fB\.foo\.bar\fR is equivalent to \fB\.foo|\.bar\fR\.330A filter of the form \fB\.foo\.bar\fR is equivalent to \fB\.foo | \.bar\fR\.331.332.P333The \fB\.foo\fR syntax only works for simple, identifier\-like keys, that is, keys that are all made of alphanumeric characters and underscore, and which do not start with a digit\.334.
79 unmodified lines
414.415.IP "" 0416.417.SS "Array/String Slice: \.[<number>:<number>]"418The \fB\.[<number>:<number>]\fR syntax can be used to return a subarray of an array or substring of a string\. The array returned by \fB\.[10:15]\fR will be of length 5, containing the elements from index 10 (inclusive) to index 15 (exclusive)\. Either index may be negative (in which case it counts backwards from the end of the array), or omitted (in which case it refers to the start or end of the array)\.418The \fB\.[<number>:<number>]\fR syntax can be used to return a subarray of an array or substring of a string\. The array returned by \fB\.[10:15]\fR will be of length 5, containing the elements from index 10 (inclusive) to index 15 (exclusive)\. Either index may be negative (in which case it counts backwards from the end of the array), or omitted (in which case it refers to the start or end of the array)\. Indices are zero\-based\.419.420.IP "" 4421.422.nf
18 unmodified lines
441.442.IP "" 0443.444.SS "Array/Object Value Iterator: \.[]"445If you use the \fB\.[index]\fR syntax, but omit the index entirely, it will return \fIall\fR of the elements of an array\. Running \fB\.[]\fR with the input \fB[1,2,3]\fR will produce the numbers as three separate results, rather than as a single array\.445If you use the \fB\.[index]\fR syntax, but omit the index entirely, it will return \fIall\fR of the elements of an array\. Running \fB\.[]\fR with the input \fB[1,2,3]\fR will produce the numbers as three separate results, rather than as a single array\. A filter of the form \fB\.foo[]\fR is equivalent to \fB\.foo | \.[]\fR\.446.447.P448You can also use this on an object, and it will return all the values of the object\.449.
8 unmodified lines
458jq \'\.[]\'459 []460=> 461462jq \'\.foo[]\'463 {"foo":[1,2,3]}464=> 1, 2, 3465466jq \'\.[]\'467 {"a": 1, "b": 1}468=> 1, 1469.
1 unmodified line
471.472.IP "" 0473.474.SS "\.[]?"471Like \fB\.[]\fR, but no errors will be output if \. is not an array or object\.475Like \fB\.[]\fR, but no errors will be output if \. is not an array or object\. A filter of the form \fB\.foo[]?\fR is equivalent to \fB\.foo | \.[]?\fR\.476.477.SS "Comma: ,"478If two filters are separated by a comma, then the same input will be fed into both and the two filters\' output value streams will be concatenated in order: first, all of the outputs produced by the left expression, and then all of the outputs produced by the right\. For instance, filter \fB\.foo, \.bar\fR, produces both the "foo" fields and "bar" fields as separate outputs\.479.
228 unmodified lines
708.709.IP "" 0710.711.SS "Recursive Descent: \.\."708Recursively descends \fB\.\fR, producing every value\. This is the same as the zero\-argument \fBrecurse\fR builtin (see below)\. This is intended to resemble the XPath \fB//\fR operator\. Note that \fB\.\.a\fR does not work; use \fB\.\.|\.a\fR instead\. In the example below we use \fB\.\.|\.a?\fR to find all the values of object keys "a" in any object found "below" \fB\.\fR\.712Recursively descends \fB\.\fR, producing every value\. This is the same as the zero\-argument \fBrecurse\fR builtin (see below)\. This is intended to resemble the XPath \fB//\fR operator\. Note that \fB\.\.a\fR does not work; use \fB\.\. | \.a\fR instead\. In the example below we use \fB\.\. | \.a?\fR to find all the values of object keys "a" in any object found "below" \fB\.\fR\.713.714.P715This is particularly useful in conjunction with \fBpath(EXP)\fR (also see below) and the \fB?\fR operator\.716.717.IP "" 4718.719.nf720717jq \'\.\.|\.a?\'721jq \'\.\. | \.a?\'722 [[{"a":1}]]723=> 1724.725.fi
503 unmodified lines
1229.fi1230.1231.IP "" 01232.1229.SS "error(message)"1230Produces an error, just like \fB\.a\fR applied to values other than null and objects would, but with the given message as the error\'s value\. Errors can be caught with try/catch; see below\.1233.SS "error, error(message)"1234Produces an error with the input value, or with the message given as the argument\. Errors can be caught with try/catch; see below\.1235.1236.P1237When the error value is \fBnull\fR, it produces nothing and works just like \fBempty\fR\. So \fB[null | error]\fR and \fB[error(null)]\fR both emit \fB[]\fR\.1238.1239.IP "" 41240.1241.nf12421243jq \'try error catch \.\'1244 "error message"1245=> "error message"12461247jq \'try error("invalid value: \e(\.)") catch \.\'1248 421249=> "invalid value: 42"1250.1251.fi1252.1253.IP "" 01254.1255.SS "halt"1256Stops the jq program with no further outputs\. jq will exit with exit status \fB0\fR\.1257.1258.SS "halt_error, halt_error(exit_code)"
335 unmodified lines
1594.P1595The ordering for objects is a little complex: first they\'re compared by comparing their sets of keys (as arrays in sorted order), and if their keys are equal then the values are compared key by key\.1596.1597.P1575\fBsort\fR may be used to sort by a particular field of an object, or by applying any jq filter\.1598\fBsort_by\fR may be used to sort by a particular field of an object, or by applying any jq filter\. \fBsort_by(f)\fR compares two elements by comparing the result of \fBf\fR on each element\. When \fBf\fR produces multiple values, it firstly compares the first values, and the second values if the first values are equal, and so on\.1599.1577.P1578\fBsort_by(f)\fR compares two elements by comparing the result of \fBf\fR on each element\.1579.1600.IP "" 41601.1602.nf1603
1 unmodified line
1605 [8,3,null,6]1606=> [null,3,6,8]16071608jq \'sort_by(\.foo)\'1589 [{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]1590=> [{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]1609 [{"foo":4, "bar":10}, {"foo":3, "bar":10}, {"foo":2, "bar":1}]1610=> [{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":4, "bar":10}]16111612jq \'sort_by(\.foo, \.bar)\'1613 [{"foo":4, "bar":10}, {"foo":3, "bar":20}, {"foo":2, "bar":1}, {"foo":3, "bar":10}]1614=> [{"foo":2, "bar":1}, {"foo":3, "bar":10}, {"foo":3, "bar":20}, {"foo":4, "bar":10}]1615.1616.fi1617.1618.IP "" 0
143 unmodified lines
1762jq \'index(", ")\'1763 "a,b, cd, efg, hijk"1764=> 317651766jq \'index(1)\'1767 [0,1,2,1,3,1,4]1768=> 117691770jq \'index([1,2])\'1771 [0,1,2,3,1,4,2,5,1,2,6,7]1772=> 117731774jq \'rindex(", ")\'1775 "a,b, cd, efg, hijk"1776=> 1217771778jq \'rindex(1)\'1779 [0,1,2,1,3,1,4]1780=> 517811782jq \'rindex([1,2])\'1783 [0,1,2,3,1,4,2,5,1,2,6,7]1784=> 81785.1786.fi1787.1788.IP "" 0
282 unmodified lines
2071.P2072When called without an argument, \fBrecurse\fR is equivalent to \fBrecurse(\.[]?)\fR\.2073.2074.P2035\fBrecurse(f)\fR is identical to \fBrecurse(f; \. != null)\fR and can be used without concerns about recursion depth\.2075\fBrecurse(f)\fR is identical to \fBrecurse(f; true)\fR and can be used without concerns about recursion depth\.2076.2077.P2078\fBrecurse(f; condition)\fR is a generator which begins by emitting \. and then emits in turn \.|f, \.|f|f, \.|f|f|f, \.\.\. so long as the computed value satisfies the condition\. For example, to generate all the integers, at least in principle, one could write \fBrecurse(\.+1; true)\fR\.2079.
1223 unmodified lines
3303.3304.P3305For example, in the following expression there is a binding which is visible "to the right" of it, \fB\.\.\. | \.*3 as $times_three | [\. + $times_three] | \.\.\.\fR, but not "to the left"\. Consider this expression now, \fB\.\.\. | (\.*3 as $times_three | [\. + $times_three]) | \.\.\.\fR: here the binding \fB$times_three\fR is \fInot\fR visible past the closing parenthesis\.3306.3267.SS "Reduce"3268The \fBreduce\fR syntax in jq allows you to combine all of the results of an expression by accumulating them into a single answer\. As an example, we\'ll pass \fB[3,2,1]\fR to this expression:3269.3270.IP "" 43271.3272.nf32733274reduce \.[] as $item (0; \. + $item)3275.3276.fi3277.3278.IP "" 03279.3280.P3281For each result that \fB\.[]\fR produces, \fB\. + $item\fR is run to accumulate a running total, starting from 0\. In this example, \fB\.[]\fR produces the results 3, 2, and 1, so the effect is similar to running something like this:3282.3283.IP "" 43284.3285.nf328632870 | (3 as $item | \. + $item) |3288 (2 as $item | \. + $item) |3289 (1 as $item | \. + $item)32903291jq \'reduce \.[] as $item (0; \. + $item)\'3292 [10,2,5,3]3293=> 203294.3295.fi3296.3297.IP "" 03298.3307.SS "isempty(exp)"3308Returns true if \fBexp\fR produces no outputs, false otherwise\.3309.3310.IP "" 4
2 unmodified lines
33133314jq \'isempty(empty)\'3315 null3316=> true33173318jq \'isempty(\.[])\'3319 []3320=> true33213322jq \'isempty(\.[])\'3323 [1,2,3]3324=> false3325.3326.fi3327.3328.IP "" 0
48 unmodified lines
3377.fi3378.3379.IP "" 03380.3381.SS "reduce"3382The \fBreduce\fR syntax allows you to combine all of the results of an expression by accumulating them into a single answer\. The form is \fBreduce EXP as $var (INIT; UPDATE)\fR\. As an example, we\'ll pass \fB[1,2,3]\fR to this expression:3383.3384.IP "" 43385.3386.nf33873388reduce \.[] as $item (0; \. + $item)3389.3390.fi3391.3392.IP "" 03393.3394.P3395For each result that \fB\.[]\fR produces, \fB\. + $item\fR is run to accumulate a running total, starting from 0 as the input value\. In this example, \fB\.[]\fR produces the results \fB1\fR, \fB2\fR, and \fB3\fR, so the effect is similar to running something like this:3396.3397.IP "" 43398.3399.nf340034010 | 1 as $item | \. + $item |3402 2 as $item | \. + $item |3403 3 as $item | \. + $item34043405jq \'reduce \.[] as $item (0; \. + $item)\'3406 [1,2,3,4,5]3407=> 1534083409jq \'reduce \.[] as [$i,$j] (0; \. + $i * $j)\'3410 [[1,2],[3,4],[5,6]]3411=> 4434123413jq \'reduce \.[] as {$x,$y} (null; \.x += $x | \.y += [$y])\'3414 [{"x":"a","y":1},{"x":"b","y":2},{"x":"c","y":3}]3415=> {"x":"abc","y":[1,2,3]}3416.3417.fi3418.3419.IP "" 03420.3421.SS "foreach"3366The \fBforeach\fR syntax is similar to \fBreduce\fR, but intended to allow the construction of \fBlimit\fR and reducers that produce intermediate results (see example)\.3422The \fBforeach\fR syntax is similar to \fBreduce\fR, but intended to allow the construction of \fBlimit\fR and reducers that produce intermediate results\.3423.3424.P3369The form is \fBforeach EXP as $var (INIT; UPDATE; EXTRACT)\fR\. Like \fBreduce\fR, \fBINIT\fR is evaluated once to produce a state value, then each output of \fBEXP\fR is bound to \fB$var\fR, \fBUPDATE\fR is evaluated for each output of \fBEXP\fR with the current state and with \fB$var\fR visible\. Each value output by \fBUPDATE\fR replaces the previous state\. Finally, \fBEXTRACT\fR is evaluated for each new state to extract an output of \fBforeach\fR\.3425The form is \fBforeach EXP as $var (INIT; UPDATE; EXTRACT)\fR\. As an example, we\'ll pass \fB[1,2,3]\fR to this expression:3426.3427.IP "" 43428.3429.nf34303431foreach \.[] as $item (0; \. + $item; [$item, \. * 2])3432.3433.fi3434.3435.IP "" 03436.3437.P3372This is mostly useful only for constructing \fBreduce\fR\- and \fBlimit\fR\-like functions\. But it is much more general, as it allows for partial reductions (see the example below)\.3438Like the \fBreduce\fR syntax, \fB\. + $item\fR is run for each result that \fB\.[]\fR produces, but \fB[$item, \. * 2]\fR is run for each intermediate values\. In this example, since the intermediate values are \fB1\fR, \fB3\fR, and \fB6\fR, the \fBforeach\fR expression produces \fB[1,2]\fR, \fB[2,6]\fR, and \fB[3,12]\fR\. So the effect is similar to running something like this:3439.3440.IP "" 43441.3442.nf34433378jq \'[foreach \.[] as $item ([[],[]]; if $item == null then [[],\.[0]] else [(\.[0] + [$item]),[]] end; if $item == null then \.[1] else empty end)]\'3379 [1,2,3,4,null,"a","b",null]3380=> [[1,2,3,4],["a","b"]]34440 | 1 as $item | \. + $item | [$item, \. * 2],3445 2 as $item | \. + $item | [$item, \. * 2],3446 3 as $item | \. + $item | [$item, \. * 2]3447.3448.fi3449.3450.IP "" 03451.3452.P3453When \fBEXTRACT\fR is omitted, the identity filter is used\. That is, it outputs the intermediate values as they are\.3454.3455.IP "" 43456.3457.nf34583459jq \'foreach \.[] as $item (0; \. + $item)\'3460 [1,2,3,4,5]3461=> 1, 3, 6, 10, 1534623463jq \'foreach \.[] as $item (0; \. + $item; [$item, \. * 2])\'3464 [1,2,3,4,5]3465=> [1,2], [2,6], [3,12], [4,20], [5,30]34663467jq \'foreach \.[] as $item (0; \. + 1; {index: \., $item})\'3468 ["foo", "bar", "baz"]3469=> {"index":1,"item":"foo"}, {"index":2,"item":"bar"}, {"index":3,"item":"baz"}3470.3471.fi3472.3473.IP "" 03474.3475.SS "Recursion"3476As described above, \fBrecurse\fR uses recursion, and any jq function can be recursive\. The \fBwhile\fR builtin is also implemented in terms of recursion\.3477.3478.P
83 unmodified lines
3562.SS "input"3563Outputs one new input\.3564.3565.P3477Note that when using \fBinput\fR it is generally be necessary to invoke jq with the \-n command\-line option, otherwise the first entity will be lost\.3566Note that when using \fBinput\fR it is generally be necessary to invoke jq with the \fB\-n\fR command\-line option, otherwise the first entity will be lost\.3567.3568.IP "" 43569.3570.nf35713572echo 1 2 3 4 | jq \'[\., input]\' # [1,2] [3,4]3573.3574.fi3575.3576.IP "" 03577.3578.SS "inputs"3579Outputs all remaining inputs, one by one\.3580.3581.P3483This is primarily useful for reductions over a program\'s inputs\. Note that when using \fBinputs\fR it is generally necessary to invoke jq with the \-n command\-line option, otherwise the first entity will be lost\.3582This is primarily useful for reductions over a program\'s inputs\. Note that when using \fBinputs\fR it is generally necessary to invoke jq with the \fB\-n\fR command\-line option, otherwise the first entity will be lost\.3583.3584.IP "" 43585.3586.nf35873588echo 1 2 3 | jq \-n \'reduce inputs as $i (0; \. + $i)\' # 63589.3590.fi3591.3592.IP "" 03593.3594.SS "debug, debug(msgs)"3595These two filters are like \fB\.\fR but have as a side\-effect the production of one or more messages on stderr\.3596.3597.P
72 unmodified lines
3670.IP "" 43671.3672.nf36733565jq \'[1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])]\'3674jq \'truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])\'3675 13567=> [[[0],2],[[0]]]3676=> [[0],2], [[0]]3677.3678.fi3679.3680.IP "" 0
392 unmodified lines