【问题标题】:Replace multiple values in json during run time [closed]在运行时替换json中的多个值[关闭]
【发布时间】:2021-08-24 00:21:58
【问题描述】:

旧 JSON 文件:

{
"firstName": "Rajesh",
"lastName": "Kumar",
"gender": "man",
"age": 24,
"address": {
    "streetAddress": "126 Udhna",
    "city": "Surat",
    "state": "GJ",
    "postalCode": "394221"
},
"phoneNumbers": [
    { "type": "home", "number": "7383627627" }
]
}

新的应该是:

{
"firstName": "Raghunath",
"lastName": "Dhara",
"gender": "man",
"age": 25,
"address": {
    "streetAddress": "126 Udhna",
    "city": "Surat",
    "state": "GJ",
    "postalCode": "394221"
},
"phoneNumbers": [
    { "type": "home", "number": "7383627627" }
]
}

请帮我替换 JSON 文件中的多个值。自 7 天以来,我一直在为此苦苦挣扎。

【问题讨论】:

标签: json bash shell


【解决方案1】:
jq --arg first Raghunath --arg last Dhara --arg age 25 '.firstName = $first | .lastName = $last | .age = $age' file.json

【讨论】:

  • 我想在哪里使用变量
  • 那就这样吧:jq --arg first "$newFirstName" ...
猜你喜欢
  • 1970-01-01
  • 2021-12-17
  • 1970-01-01
  • 1970-01-01
  • 2017-08-23
  • 1970-01-01
  • 2018-06-06
  • 2013-10-08
  • 2017-08-31
相关资源
最近更新 更多