Building upon earlier posts, I wanted to streamline the output from a REST API that returns a list of running containers: -
curl -s -k -X GET https://my.endpoint.com/containers -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer '"$ACCESS_TOKEN" | jq '.data[] | select (.Names[] | contains("dave"))' | jq .Names
[
"/davehay_k8s_worker_1"
]
[
"/davehay_k8s_master"
]
[
"/davehay_k8s_worker_2"
]
Specifically, I wanted to remove the extraneous square brackets and double quotes ...
Here we go ...
curl -s -k -X GET https://my.endpoint.com/containers -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer '"$ACCESS_TOKEN" | jq '.data[] | select (.Names[] | contains("dave"))' | jq -r .Names[]
/davehay_k8s_worker_1
/davehay_k8s_master
/davehay_k8s_worker_2
As with everything, there's a better way ....
But this works for me :-)
No comments:
Post a Comment