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
Provenance
- Commit
931a362- Tree
e157d7d- Author
Thomas Sibley <tom@zulutango.org>- Committer
GitHub <noreply@github.com>- Parent
a8f27cc
4 files changed+22 added−22 removed
modified:docs/content/manual/dev/manual.yml+6 added-6 removed
3382 unmodified lines3383 have `[<path>, <leaf-value>]` (and a few other forms) as inputs.3384 3385 Several builtins are provided to make handling streams easier.3386 3387- 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]]`.3389 3390 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 jq8 unmodified lines3401 number of path elements from the left of the outputs of the3402 given streaming expression.3403 3404 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]]']3408 3409 - title: "`fromstream(stream_expression)`"3410 body: |3411 3412 Outputs values corresponding to the stream expression's3413 outputs.3414 3415 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"]']3419 3420 - title: "`tostream`"3421 body: |3422 410 unmodified linesmodified:docs/content/manual/v1.7/manual.yml+6 added-6 removed
3315 unmodified lines3316 have `[<path>, <leaf-value>]` (and a few other forms) as inputs.3317 3318 Several builtins are provided to make handling streams easier.3319 3320- 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]]`.3322 3323 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 jq8 unmodified lines3334 number of path elements from the left of the outputs of the3335 given streaming expression.3336 3337 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]]']3341 3342 - title: "`fromstream(stream_expression)`"3343 body: |3344 3345 Outputs values corresponding to the stream expression's3346 outputs.3347 3348 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"]']3352 3353 - title: "`tostream`"3354 body: |3355 347 unmodified linesmodified:tests/man.test+4 added-4 removed
940 unmodified lines941 def while(cond; update): def _while: if cond then ., (update | _while) else empty end; _while; [while(.<100; .*2)]942 1943 [1,2,4,8,16,32,64]944 945-truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])945+truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])946 1947-[[0],2]947+[[0],"b"]948 [[0]]949 950-fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))950+fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))951 null952-[2]952+["b"]953 954 . as $dot|fromstream($dot|tostream)|.==$dot955 [0,[1,{"a":1},{"b":2}]]956 true27 unmodified linesmodified: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 lines3790 .P3791 Several builtins are provided to make handling streams easier\.3792 .3793 .P3794-The examples below use the streamed form of \fB[0,[1]]\fR, which is \fB[[0],0],[[1,0],1],[[1,0]],[[1]]\fR\.3794+The 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 .P3797 Streaming 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 lines3802 .IP "" 43803 .3804 .nf3805 3806-jq \'truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])\'3806+jq \'truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])\'3807 13808-=> [[0],2], [[0]]3808+=> [[0],"b"], [[0]]3809 .3810 .fi3811 .3812 .IP "" 04 unmodified lines3817 .IP "" 43818 .3819 .nf3820 3821-jq \'fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))\'3821+jq \'fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))\'3822 null3823-=> [2]3823+=> ["b"]3824 .3825 .fi3826 .3827 .IP "" 0445 unmodified lines