Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 521

How to append object into a list of objects (not array) using bash

$
0
0

To a list of objects [{..},{..}], I want to add a new object using bash.Example of my list:

[      {"name" : "server","image" : "server:latest","essential" : true,"environment" : concat(          [            {"name" : "TZ","value" : "${var.env_timezone}"            }          ],          [            for key, value in var.env_for_server:            {"name" : key,"value" : value            }          ]        ,"portMappings" : [          {"hostPort" : 3000,"protocol" : "tcp","containerPort" : 3000          }        ],      },      {"name" : "client","image" : "client:latest"      },      {"name" : "nginx_gateway","image" : "nginx_gateway:latest","essential" : true,"portMappings" : [          {"hostPort" : 80,"protocol" : "tcp","containerPort" : 80          }        ]      } ]

To this, adding:

{"name": "sidecar","image": "sidecar:latest","essential": true}

So the result will be:

[      {"name" : "server","image" : "server:latest","essential" : true,"environment" : concat(          [            {"name" : "TZ","value" : "${var.env_timezone}"            }          ],          [            for key, value in var.env_for_server:            {"name" : key,"value" : value            }          ]        ,"portMappings" : [          {"hostPort" : 3000,"protocol" : "tcp","containerPort" : 3000          }        ],      },      {"name" : "client","image" : "client:latest"      },      {"name" : "nginx_gateway","image" : "nginx_gateway:latest","essential" : true,"portMappings" : [          {"hostPort" : 80,"protocol" : "tcp","containerPort" : 80          }        ]      },      {"name": "sidecar","image": "sidecar:latest","essential": true      } ]

I'm working on CI, so better to keep it one-two lines of code max.Already tried some commands of jq, but nothing came out with merged, so trying my lucky in here.

Something like that when the files are respectively

jq '. += [input]' existing_containers.json new_container.json > updated_containers.json

Viewing all articles
Browse latest Browse all 521

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>