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
  • 89,455
  • 62
  • 89
  • 125

1 Answers1

2
jq --arg first Raghunath --arg last Dhara --arg age 25 '.firstName = $first | .lastName = $last | .age = $age' file.json
glenn jackman
  • 238,783
  • 38
  • 220
  • 352