![](/img/trans.png)
[英]Using jq to produce one line of output per array element in a json object that also includes other fields from the json object
[英]one json object per line with jq from a large json file
这是我的 json 文件:
[
{
"name": "1"
},
{
"name": "2"
},
{
"name": "3"
},
{
"name": "4"
}
]
我想在一个文件中逐行获取所有 object:
{"name":"1"}
{"name":"2"}
{"name":"3"}
{"name":"4"}
我的文件很大,我正在使用 stream 选项。
到目前为止,这是我的尝试:
jq --stream -c '.[]' car.json > result.json
但它给了我:
[0,"name"]
"1"
[1,"name"]
"2"
jq 常见问题解答中涵盖了该主题。 对于您描述的情况,您可能可以使用此处给出的两种可能性中较简单的一种:
jq -cn --stream 'fromstream(1|truncate_stream(inputs))'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.