JQ将数据从1个文件推送到另一个文件的嵌套数组中

问题描述 投票:0回答:1

我有2个文件:

f1.json

{
  "a.b": {
    "c": [ 1, 2 ]
  },
  "d": "other data"
}

f1.json

{
  "a.b": {
    "c": [ 3, 4 ]
  }
}

[[f2.json中的嵌套数组的所有详细信息应合并到f1.json中,如下所示

f1.json:

{ "a.b": { "c": [ 1, 2, 3, 4 ] }, "d": "other data" }
在f1.json中定位数组:

jq -s'。[0] [“ a.b”]。c f1.json

访问f2.json中的数组(因为这将是一个静态文件,所以我们不必依赖于a.b的特定名称):

jq。[]。c f2.json

arrays file nested add jq
1个回答
0
投票
j2.json用作--argfile中的参考,并在处理j1.json时将数组内容加在一起

jq --argfile sec f2.json '."a.b".c += $sec."a.b".c' f1.json

© www.soinside.com 2019 - 2024. All rights reserved.