【发布时间】:2021-08-26 10:07:18
【问题描述】:
我有这个 JSON
{
"firstName": "Rajesh",
"lastName": "Kumar",
"gender": "man",
"age": 24,
"address": {
"streetAddress": "126 Udhna",
"city": "Surat",
"state": "WB",
"postalCode": "394221"
},
"phoneNumbers": [
{
"type": "home",
"number": "7383627627"
}
]
}
我需要使用 JQ 找到“状态”键的值并替换 JSON 中的值。我不想通过提供键的位置来获取它,喜欢
firstName=$(cat sample-json.json | jq -r '.firstName')
我的预期输出
{
"firstName": "Rajesh",
"lastName": "Kumar",
"gender": "man",
"age": 24,
"address": {
"streetAddress": "126 Udhna",
"city": "Surat",
"state": "Bihar",
"postalCode": "394221"
},
"phoneNumbers": [
{
"type": "home",
"number": "7383627627"
}
]
}
【问题讨论】:
-
那你想怎么获取呢?
-
所以你想改变
state键的值?