json file as follows:
{\"name\" :\"sam\",
\"age\":23,
\"designation\":\"doctor\"}
now i want to add another json object {\"location\":\"can
To merge two json objects, you could use jq command-line utility:
$ jq -s add sample.json another.json
Output:
{
"name": "sam",
"age": 23,
"designation": "doctor",
"location": "canada"
}
To update a single attribute:
$ jq '.location="canada"' sample.json
It produces the same output.
To prepend "doctor"
to the location:
$ jq '.location = "doctor" + .location' input.json
Output:
{
"name": "sam",
"age": 23,
"designation": "doctor",
"location": "doctorcanada"
}
sed -i '$s/}/,\n"location":"canada"}/' sample.json
Result:
{"name" :"sam",
"age":23,
"designation":"doctor",
"location":"canada"}