JQ select
Using the following payload (in this case derived from ccloud environment list -o json
[ { "id": "t27422", "name": "dev" }, { "id": "env-ygg7j", "name": "spike" } ]
ccloud environment list -o json | jq .[]
{ "id": "t27422", "name": "dev" } { "id": "env-ygg7j", "name": "spike" }
ccloud environment list -o json | jq .[].name
"dev" "spike"
ccloud environment list -o json | jq -c '[ .[] | select( .name | contains("spike")) ]’
[{"id":"env-ygg7j","name":"spike"}]
ccloud environment list -o json | jq '.[] | select(.name | contains("spike")) .id’
"env-ygg7j"
Get rid of quotes with -r
ccloud environment list -o json | jq -r '.[] | select(.name | contains("spike")) .id’
env-ygg7j
The above can also be written as follows if you’re having bother with jq and a message similar to Cannot index boolean with string “id"
ccloud environment list -o json | jq -r '.[] | select(.name | contains ("spike")) | .id'