edit - How do I update a single value in a nested array of objects in a json document using jq? -


i have json document looks following. note simplified example of real json, included @ bottom of question:

{   "some_array": [     {       "k1": "a",       "k2": "xxx"     },     {       "k1": "b",       "k2": "yyy"     }   ] } 

i change value of k2 keys in some_array array value of k1 key "b".

is possible using jq ?

for reference actual json document, environment variable file use in postman / newman tool. attempting conversion using jq because tool not yet support command line overrides of specific environment variables

actual json

{   "name": "local-stack-env-config",   "values": [     {       "enabled": true,       "key": "kc_master_host",       "type": "text",       "value": "http://localhost:8087"     },     {       "enabled": true,       "key": "kc_user_guid",       "type": "text",       "value": "11111111-1111-1111-1111-11111111111"     }   ],   "timestamp": 1502768145037,   "_postman_variable_scope": "environment",   "_postman_exported_at": "2017-08-15t03:36:41.474z",   "_postman_exported_using": "postman/5.1.3" } 

here simpler version of zayquan's filter:

.some_array |= map(if .k1=="b" .k2="changed" else . end) 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -