Created
January 22, 2021 09:53
-
-
Save unpluggedcoder/04fbf08fc81dbd6c0a49fd542faf52b1 to your computer and use it in GitHub Desktop.
for loop with jq in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for object in array | |
# Thanks to https://www.starkandwayne.com/blog/bash-for-loop-over-json-array-using-jq/ | |
example='[{"name":"foo"},{"name":"bar"}]' | |
for row in $(echo "${example}" | jq -rc '.[] | @base64'); do | |
_jq() { | |
echo ${row} | base64 --decode | jq -r ${1} | |
} | |
# usage: $(_jq '.xxx') | |
echo $(_jq '.name') | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment