Skip to content
Myr

docs: Use a better input example in the streaming section (#3322)

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

The introduction says all the usage examples (e.g. of truncate_stream, etc) in the section use [0,[1]] as input, but they actually use [1,[2]]. ["a",["b"]] seems better than [1,[2]] as the string values won't be confusable with the indexes in <path>.

authored by Thomas Sibley · committed by GitHub · parent a8f27cc · Browse files · 4 files+22 added−22 removed
This commit

State

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

Diff stats

4 files+22 added−22 removed

  • tests:+4 added−4 removed
  • other:+18 added−18 removed

4 files+22 added−22 removed

modified:docs/content/manual/dev/manual.yml+6 added-6 removed
3382 unmodified lines
3383 have `[<path>, <leaf-value>]` (and a few other forms) as inputs.33843385 Several builtins are provided to make handling streams easier.33863387 The examples below use the streamed form of `[0,[1]]`, which is3388 `[[0],0],[[1,0],1],[[1,0]],[[1]]`.3387 The examples below use the streamed form of `["a",["b"]]`, which is3388 `[[0],"a"],[[1,0],"b"],[[1,0]],[[1]]`.33893390 Streaming forms include `[<path>, <leaf-value>]` (to indicate any3391 scalar value, empty array, or empty object), and `[<path>]` (to3392 indicate the end of an array or object). Future versions of jq
8 unmodified lines
3401 number of path elements from the left of the outputs of the3402 given streaming expression.34033404 examples:3405 - program: 'truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])'3405 - program: 'truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])'3406 input: '1'3407 output: ['[[0],2]', '[[0]]']3407 output: ['[[0],"b"]', '[[0]]']34083409 - title: "`fromstream(stream_expression)`"3410 body: |34113412 Outputs values corresponding to the stream expression's3413 outputs.34143415 examples:3416 - program: 'fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))'3416 - program: 'fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))'3417 input: 'null'3418 output: ['[2]']3418 output: ['["b"]']34193420 - title: "`tostream`"3421 body: |3422
410 unmodified lines
modified:docs/content/manual/v1.7/manual.yml+6 added-6 removed
3315 unmodified lines
3316 have `[<path>, <leaf-value>]` (and a few other forms) as inputs.33173318 Several builtins are provided to make handling streams easier.33193320 The examples below use the streamed form of `[0,[1]]`, which is3321 `[[0],0],[[1,0],1],[[1,0]],[[1]]`.3320 The examples below use the streamed form of `["a",["b"]]`, which is3321 `[[0],"a"],[[1,0],"b"],[[1,0]],[[1]]`.33223323 Streaming forms include `[<path>, <leaf-value>]` (to indicate any3324 scalar value, empty array, or empty object), and `[<path>]` (to3325 indicate the end of an array or object). Future versions of jq
8 unmodified lines
3334 number of path elements from the left of the outputs of the3335 given streaming expression.33363337 examples:3338 - program: "truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])"3338 - program: 'truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])'3339 input: "1"3340 output: ["[[0],2]", "[[0]]"]3340 output: ['[[0],"b"]', '[[0]]']33413342 - title: "`fromstream(stream_expression)`"3343 body: |33443345 Outputs values corresponding to the stream expression's3346 outputs.33473348 examples:3349 - program: "fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))"3349 - program: 'fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))'3350 input: "null"3351 output: ["[2]"]3351 output: ['["b"]']33523353 - title: "`tostream`"3354 body: |3355
347 unmodified lines
modified:tests/man.test+4 added-4 removed
940 unmodified lines
941def while(cond; update): def _while: if cond then ., (update | _while) else empty end; _while; [while(.<100; .*2)]9421943[1,2,4,8,16,32,64]944945truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])945truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])9461947[[0],2]947[[0],"b"]948[[0]]949950fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))950fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))951null952[2]952["b"]953954. as $dot|fromstream($dot|tostream)|.==$dot955[0,[1,{"a":1},{"b":2}]]956true
27 unmodified lines
modified:jq.1.prebuilt+6 added-6 removed
1.2.TH "JQ" "1" "January 2025" "" ""2.TH "JQ" "1" "May 2025" "" ""3.4.SH "NAME"5\fBjq\fR \- Command\-line JSON processor6.
3783 unmodified lines
3790.P3791Several builtins are provided to make handling streams easier\.3792.3793.P3794The examples below use the streamed form of \fB[0,[1]]\fR, which is \fB[[0],0],[[1,0],1],[[1,0]],[[1]]\fR\.3794The examples below use the streamed form of \fB["a",["b"]]\fR, which is \fB[[0],"a"],[[1,0],"b"],[[1,0]],[[1]]\fR\.3795.3796.P3797Streaming forms include \fB[<path>, <leaf\-value>]\fR (to indicate any scalar value, empty array, or empty object), and \fB[<path>]\fR (to indicate the end of an array or object)\. Future versions of jq run with \fB\-\-stream\fR and \fB\-\-seq\fR may output additional forms such as \fB["error message"]\fR when an input text fails to parse\.3798.
3 unmodified lines
3802.IP "" 43803.3804.nf38053806jq \'truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])\'3806jq \'truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])\'3807 13808=> [[0],2], [[0]]3808=> [[0],"b"], [[0]]3809.3810.fi3811.3812.IP "" 0
4 unmodified lines
3817.IP "" 43818.3819.nf38203821jq \'fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))\'3821jq \'fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))\'3822 null3823=> [2]3823=> ["b"]3824.3825.fi3826.3827.IP "" 0
445 unmodified lines