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.

1

1 Answer 1

2
jq --arg first Raghunath --arg last Dhara --arg age 25 '.firstName = $first | .lastName = $last | .age = $age' file.json
Sign up to request clarification or add additional context in comments.

2 Comments

I would like to use variables where
So do that: jq --arg first "$newFirstName" ...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.