我一直在尝试以编程方式更新AWS Route 53 DNS记录,因此我一直在使用jq来更新以下JSON文件;
{
"Comment": "Update 'A' record for drivepoc.biz zone file",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "www.domain.biz.",
"Type": "A",
"TTL": 60,
"ResourceRecords": [
{
"Value": "123.123.123.123"
}
]
}
}
]
}
因此,现有条目"Value": "123.123.123.123"
需要保留,但需要额外输入"Value": "456.456.456.456"
。我最接近的是:
cat a_record.json | jq '.Changes[0].ResourceRecordSet.ResourceRecords |= .+ ["Value: 456.456.456.456"]'
但这会把它放在大括号之外,引号错了;
"ResourceRecords": [
{
"Value": "52.18.219.57"
},
"Value": "456.456.456.456"
]
而不是所需要的;
"ResourceRecords": [
{
"Value": "52.18.219.57"
},
{
"Value": "456.456.456.456"
}
]
有人可以给我任何提示吗?
答案 0 :(得分:2)
您正在向该数组添加对象,而不是字符串。创建一个要插入的对象。
.Changes[].ResourceRecordSet.ResourceRecords += [{Value:"456.456.456.456"}]