首页 > 解决方案 > jq simple json object merge/combination

问题描述

a.json

{"a": 1}

b.json

{"b": 1}

Desired outcome

{"a": 1, "b": 1}

jq -s "." a.json b.json

[
  {
    "a": 1
  },
  {
    "b": 1
  }
]

It's wrapped in an array


jq "." a.json b.json

{
  "a": 1
}
{
  "b": 1
}

That's not even valid json


Is jq the wrong tool here? What is more appropriate?

标签: jsonobjectmergeaddjq

解决方案


Try:

jq -s 'add' a.json b.json

Result:

{
  "a": 1,
  "b": 1
}

推荐阅读