0

Old JSON File:

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

New Should be:

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

Please help me to replace multiple values in JSON file. I am struggling with this since 7 days.

Toto
  • 86,179
  • 61
  • 85
  • 118

1 Answers1

1
jq --arg first Raghunath --arg last Dhara --arg age 25 '.firstName = $first | .lastName = $last | .age = $age' file.json
glenn jackman
  • 223,850
  • 36
  • 205
  • 328