问题
有2个json文件,我想使用jq工具将他们合并成一个
1.json
{
"registry-mirrors": [
"https://abcdefgfh.mirror.aliyuncs.com"
],
"a": "bc",
"c": "d"
}
2.json
{
"registry-mirrors": [
"http://127.0.0.1:5000"
],
"insecure-registries": [
"127.0.0.1:5000"
]
}
我想要达到的结果
{
"registry-mirrors": [
"https://abcdefgfh.mirror.aliyuncs.com",
"http://127.0.0.1:5000"
],
"insecure-registries": [
"127.0.0.1:5000"
],
"a": "bc",
"c": "d"
}
我的解答思路和尝试过的方法
jq -s '[.[0]."registry-mirrors"=([.[]."registry-mirrors"]|add), .[0]."insecure-registries"=([.[]."insecure-registries"]|add)]|.[0][0]["insecure-registries"]=.[1][0]["insecure-registries"]|.[0][0]' 1.json 2.json
我研究了整整一天,惭愧啊,虽然成功了,但是这语法过于复杂