合并json文件-并入单个dict json文件

时间:2020-03-10 16:59:26

标签: json jq

这是3个JSON文件

File1

{
  "component1": [
  ]
}

File2

{
  "component2": [
  ]
}

File3

{
  "component3": [
  ]
}

找不到将该JSON文件作为jq输出的jq命令行:

{
  "components": {
     "component1": [
      ],
     "component2": [
      ],
     "component3": [
      ]
   }
}

非常感谢您的支持 最好的问候。

2 个答案:

答案 0 :(得分:1)

inputs一次遍历输入对象,然后使用components函数将其附加到reduce

jq -n 'reduce inputs as $d (.; .components += $d )' file{1..3}.json

答案 1 :(得分:1)

您可以简单地使用add,例如

jq -s '{components: add}' file{1..3}.json

或:

jq -n '{components: [inputs]|add}' file{1..3}.json