如何通过合并每个对象,使用jq将上述两个文件合并为一个数组?
我找到了combine array of objects from two files with jq under specific key 1.4,但这是针对特定密钥的。
我尝试过:
jq -n '{ combined: (transpose | map(add)) }' a.json b.json
jq: error (at <unknown>): Cannot iterate over null (null)
输入:
==> a.json <==
[
{
"datetime": "2019-12-08 11:34"
},
{
"datetime": "2019-12-08 11:35"
},
{
"datetime": "2019-12-08 12:03"
}
]
==> b.json <==
[
{
"command": "cat test.txt"
},
{
"command": "cat test2.txt"
},
{
"command": "cat test3.txt"
}
]
所需的输出:
[
{
"command": "cat test.txt",
"datetime": "2019-12-08 11:34"
},
{
"command": "cat test2.txt",
"datetime": "2019-12-08 11:35"
},
{
"command": "cat test3.txt",
"datetime": "2019-12-08 12:03"
}
]
答案 0 :(得分:1)
只是them饮他们。 -n
用于输入空值,对于此琐碎的任务来说是多余的。
jq -s 'transpose|map(add)' a.json b.json