简体   繁体   English

每行一个 json object 与来自大型 json 文件的 jq

[英]one json object per line with jq from a large json file

Here is my json file:这是我的 json 文件:

[
  {
    "name": "1"
  },
  {
    "name": "2"
  },
  {
    "name": "3"
  },
  {
    "name": "4"
  }
]

i would like to get all object in a file one by line:我想在一个文件中逐行获取所有 object:

{"name":"1"}
{"name":"2"}
{"name":"3"}
{"name":"4"}

and my file is very big and i'am using the stream option.我的文件很大,我正在使用 stream 选项。

Here is my attempt so far:到目前为止,这是我的尝试:

jq --stream -c '.[]' car.json > result.json

but it gives me:但它给了我:

[0,"name"]
"1"
[1,"name"]
"2"

This topic is covered in the jq FAQ . jq 常见问题解答中涵盖了该主题。 For the situation you describe you might be able to use the simpler of the two possibilities given there:对于您描述的情况,您可能可以使用此处给出的两种可能性中较简单的一种:

jq -cn --stream 'fromstream(1|truncate_stream(inputs))'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM