How to use `jq` to convert a json by combine some of the values? -


say have json:

{     "name":"my-project",     "projects" : [     {         "project": "core",         "configurations": [         {             "configuration": "compile",             "dependencies" : [                 {                     "organization": "a11",                     "name" : "b11",                     "version" : "1.1"                 },                 {                     "organization": "a22",                     "name" : "b22",                     "version" : "2.2",                     "dependencies" : [                          {                             "organization": "a33",                             "name" : "b33",                             "version" : "3.3"                         }                     ]                 }             ]         }         ]     }     ] } 

how can use jq convert json to:

{     "name":"my-project",     "projects" : [     {         "project": "core",         "configurations": [         {             "configuration": "compile",             "dependencies" : [                 {                     "dep" : "a11:b11:1.1"                 },                 {                     "dep": "a22:b22:2.2",                     "dependencies" : [                          {                             "dep": "a33:b33:3.3"                         }                     ]                 }             ]         }         ]     }     ] } 

with of function, can recursively.

def update_dependencies:     { dep: "\(.organization):\(.name):\(.version)" }     +     with_entries(select(.key == "dependencies") | .value |= map(update_dependencies))     ; .projects |= map(     .configurations |= map(         .dependencies |= map(update_dependencies)     ) ) 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -