docs: Use a better input example in the streaming section (#3322)
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>.
This commit is contained in:
1 parent
a8f27cc4db
commit
931a362f8b
4 files changed
+22
-22
No files matched your search
@@ -3384,8 +3384,8 @@ sections:
|
||||
|
||||
Several builtins are provided to make handling streams easier.
|
||||
|
||||
The examples below use the streamed form of `[0,[1]]`, which is
|
||||
`[[0],0],[[1,0],1],[[1,0]],[[1]]`.
|
||||
The examples below use the streamed form of `["a",["b"]]`, which is
|
||||
`[[0],"a"],[[1,0],"b"],[[1,0]],[[1]]`.
|
||||
|
||||
Streaming forms include `[<path>, <leaf-value>]` (to indicate any
|
||||
scalar value, empty array, or empty object), and `[<path>]` (to
|
||||
@@ -3402,9 +3402,9 @@ sections:
|
||||
given streaming expression.
|
||||
|
||||
examples:
|
||||
- program: 'truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])'
|
||||
- program: 'truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])'
|
||||
input: '1'
|
||||
output: ['[[0],2]', '[[0]]']
|
||||
output: ['[[0],"b"]', '[[0]]']
|
||||
|
||||
- title: "`fromstream(stream_expression)`"
|
||||
body: |
|
||||
@@ -3413,9 +3413,9 @@ sections:
|
||||
outputs.
|
||||
|
||||
examples:
|
||||
- program: 'fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))'
|
||||
- program: 'fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))'
|
||||
input: 'null'
|
||||
output: ['[2]']
|
||||
output: ['["b"]']
|
||||
|
||||
- title: "`tostream`"
|
||||
body: |
|
||||
|
||||
@@ -3317,8 +3317,8 @@ sections:
|
||||
|
||||
Several builtins are provided to make handling streams easier.
|
||||
|
||||
The examples below use the streamed form of `[0,[1]]`, which is
|
||||
`[[0],0],[[1,0],1],[[1,0]],[[1]]`.
|
||||
The examples below use the streamed form of `["a",["b"]]`, which is
|
||||
`[[0],"a"],[[1,0],"b"],[[1,0]],[[1]]`.
|
||||
|
||||
Streaming forms include `[<path>, <leaf-value>]` (to indicate any
|
||||
scalar value, empty array, or empty object), and `[<path>]` (to
|
||||
@@ -3335,9 +3335,9 @@ sections:
|
||||
given streaming expression.
|
||||
|
||||
examples:
|
||||
- program: "truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])"
|
||||
- program: 'truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])'
|
||||
input: "1"
|
||||
output: ["[[0],2]", "[[0]]"]
|
||||
output: ['[[0],"b"]', '[[0]]']
|
||||
|
||||
- title: "`fromstream(stream_expression)`"
|
||||
body: |
|
||||
@@ -3346,9 +3346,9 @@ sections:
|
||||
outputs.
|
||||
|
||||
examples:
|
||||
- program: "fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))"
|
||||
- program: 'fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))'
|
||||
input: "null"
|
||||
output: ["[2]"]
|
||||
output: ['["b"]']
|
||||
|
||||
- title: "`tostream`"
|
||||
body: |
|
||||
|
||||
Generated
+6
-6
@@ -1,5 +1,5 @@
|
||||
.
|
||||
.TH "JQ" "1" "January 2025" "" ""
|
||||
.TH "JQ" "1" "May 2025" "" ""
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBjq\fR \- Command\-line JSON processor
|
||||
@@ -3791,7 +3791,7 @@ However, streaming isn\'t easy to deal with as the jq program will have \fB[<pat
|
||||
Several builtins are provided to make handling streams easier\.
|
||||
.
|
||||
.P
|
||||
The examples below use the streamed form of \fB[0,[1]]\fR, which is \fB[[0],0],[[1,0],1],[[1,0]],[[1]]\fR\.
|
||||
The examples below use the streamed form of \fB["a",["b"]]\fR, which is \fB[[0],"a"],[[1,0],"b"],[[1,0]],[[1]]\fR\.
|
||||
.
|
||||
.P
|
||||
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\.
|
||||
@@ -3803,9 +3803,9 @@ Consumes a number as input and truncates the corresponding number of path elemen
|
||||
.
|
||||
.nf
|
||||
|
||||
jq \'truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])\'
|
||||
jq \'truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])\'
|
||||
1
|
||||
=> [[0],2], [[0]]
|
||||
=> [[0],"b"], [[0]]
|
||||
.
|
||||
.fi
|
||||
.
|
||||
@@ -3818,9 +3818,9 @@ Outputs values corresponding to the stream expression\'s outputs\.
|
||||
.
|
||||
.nf
|
||||
|
||||
jq \'fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))\'
|
||||
jq \'fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))\'
|
||||
null
|
||||
=> [2]
|
||||
=> ["b"]
|
||||
.
|
||||
.fi
|
||||
.
|
||||
|
||||
Generated
+4
-4
@@ -942,14 +942,14 @@ def while(cond; update): def _while: if cond then ., (update | _while) else empt
|
||||
1
|
||||
[1,2,4,8,16,32,64]
|
||||
|
||||
truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]])
|
||||
truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]])
|
||||
1
|
||||
[[0],2]
|
||||
[[0],"b"]
|
||||
[[0]]
|
||||
|
||||
fromstream(1|truncate_stream([[0],1],[[1,0],2],[[1,0]],[[1]]))
|
||||
fromstream(1|truncate_stream([[0],"a"],[[1,0],"b"],[[1,0]],[[1]]))
|
||||
null
|
||||
[2]
|
||||
["b"]
|
||||
|
||||
. as $dot|fromstream($dot|tostream)|.==$dot
|
||||
[0,[1,{"a":1},{"b":2}]]
|
||||
|
||||
Reference in new issue
Block a user