jq: Change multiple values
Here is a method which uses + object addition to update multiple members.
. + {two:"newtwo", three:"newthree"}
Sample Run (assumes data in data.json
)
$ jq -M '. + {two:"newtwo", three:"newthree"}' data.json
{
"one": {
"val": 1
},
"two": "newtwo",
"three": "newthree",
"four": "val"
}
Try it online at jqplay.org
Simply change the comma to a pipe character and you’re done:
.two="newval" | .three="newval"
"," is for concatenating streams: A,B
will emit A followed by B.