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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -