I have a json file test.json with below format:
{ "environments": {"egress": [ ] }}
I want to add objects under egress field with multiple variable values. I have written a bash script test.sh with below code snippet:
egress_port='[80,443]'egress_value='[test,test1]'egress_protocol='[http,https]'# IFS=','echo $egress_portecho $egress_valueecho $egress_protocolcat test.json |jq --argjson port "$egress_port" \ --argjson value "$egress_value" \ --argjson protocol "$egress_protocol" \'.environments.egress = ([$port, $value, $protocol] | transpose | map ({port: .[0], type: "external", value: .[1], protocol: .[2]}))'
I want json to be updated in below format:
{ "environments": {"egress": [ {"port": "80", "type": "external", "value": "test", "protocol": "http" }, {"port": "443", "type": "external", "value": "test1", "protocol": "https" } ] }}
When i run it, it throws an error:
jq: invalid JSON text passed to --argjson
Can someone help me here?