小编Gre*_*ard的帖子

Use jq to concatenate JSON arrays in multiple files

I have a series of JSON files containing an array of records, e.g.

$ cat f1.json
{
  "records": [
    {"a": 1},
    {"a": 3}
  ]
}

$ cat f2.json
{
  "records": [
    {"a": 2}
  ]
}
Run Code Online (Sandbox Code Playgroud)

I want to 1) extract a single field from each record and 2) output a single array containing all the field values from all input files.

The first part is easy:

jq '.records | map(.a)' f?.json
[
  1,
  3
]
[
  2
]
Run Code Online (Sandbox Code Playgroud)

But I …

json jq

1
推荐指数
3
解决办法
3056
查看次数

标签 统计

jq ×1

json ×1