json - Set multiple values -
given file
{ "[global]": { "current": "", "hash": "" } }
i output:
{ "[global]": { "current": "alpha", "hash": "bravo" } }
i have working command:
jq '."[global]".current="alpha" | ."[global]".hash="bravo"' example.json
however rather not have repeat ."[global]"
part. tried command returns part of input:
$ jq '."[global]" | .current="alpha" | .hash="bravo"' example.json { "current": "alpha", "hash": "bravo" }
the multiplication of objects recursively merges two. can merge [global]
object object new values. string values on rhs used in result.
."[global]" *= { current: "alpha", hash: "bravo" }
addtion work here too, multiplication more useful, particularly nested objects. rather replacing corresponding objects, merged.
Comments
Post a Comment