Hi i am trying in shell script to get a list of consul service tags for myApp passing nodes, using jq.
when i have something like this..
curl 'http://127.0.0.1:8500/v1/health/service/myApp?dc=a&passing=true' \
  | jq '.[].Checks[1].ServiceTags[]' 
output is..
"a"
"b"
"c"
"d"
I want to know if i could get it as a list. I want the output in this way..
 ["a","b","c","d"]
can you please suggest options..
Instead of
jq '.[].Checks[1].ServiceTags[]' 
Try
jq '[.[].Checks[1].ServiceTags[]]' 
The extra [] instruct jq to collect the values into an array.
See Array construction: [] in the jq Manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With