back to TILs

Wrapping arrays in jq

Riffing on Tom MacWright’s “Using super” post from yesterday, I saw the post and immediately thought of using jq.

I thought I might get what he was looking for with my initial attempt, something like:

$ pbpaste | jq '.[].name'
"ALGOLIA_API_KEY"
"AMAZON_AWS_ACCESS_KEY_ID"

… but that left out the wrapper array. I figured I might need some other jq function or pipe, but instead I found that you can just wrap the entire expression in square brackets to wrap the result:

$ pbpaste | jq '[.[].name]'
"ALGOLIA_API_KEY"
"AMAZON_AWS_ACCESS_KEY_ID"

Regardless, jq feels worth the investment, especially given the community (and alternative implementations) built up around it.