jq 使用输入将流减少为所有叶值的数组
我想接收流式 json 输入并将它们减少为包含叶值的数组。
演示:https://jqplay.org/s/cZxLguJFxv
请考虑
过滤器:
try reduce range(30) as $i ( []; (.+[until(length==2;input)[1]] // error(.)) )
catch empty
输入:
[
[
0,
0,
"a"
],
null
]
[
[
0,
0,
"a"
]
]
[
[
0,
1,
"b"
],
null
]
[
[
0,
1,
"b"
]
]
[
[
0,
1
]
]
[
[
1
],
0
]
...
output:
empty
我期望输出:[null, null, 0, ...]
但我却得到了空。
我告诉 reduce
迭代 30 次,但输入的大小小于该值。我期望它会清空那些长度不是 2 的输入,并生成一个包含所有叶值的数组。
我不知道当不再有长度为 2 的 input
且存在 reduce
迭代时,这将如何表现。
我想知道为什么我的过滤器返回空。我做错了什么?谢谢!
I want to receive streamed json inputs and reduce them to an array containing the leaf values.
Demo: https://jqplay.org/s/cZxLguJFxv
Please consider
filter:
try reduce range(30) as $i ( []; (.+[until(length==2;input)[1]] // error(.)) )
catch empty
input:
[
[
0,
0,
"a"
],
null
]
[
[
0,
0,
"a"
]
]
[
[
0,
1,
"b"
],
null
]
[
[
0,
1,
"b"
]
]
[
[
0,
1
]
]
[
[
1
],
0
]
...
output:
empty
I expect the output: [null, null, 0, ...]
but I get empty instead.
I told reduce
to iterate 30 times but the size of inputs is less than that. I'm expecting it will empty
those input of length other than 2 and produce an array containing all leaf values.
I don't know how this will behave when there is no more input
with length 2 left and there are iterations of reduce
left.
I want to know why my filter returns empty. What am I doing wrong? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些过滤器应该满足您的要求:
演示
演示
These filters should do what you want:
Demo
Demo