Last active
February 21, 2022 23:38
-
-
Save namp10010/c7ef51abc1b2f7f5265634d250ad8aaa to your computer and use it in GitHub Desktop.
Bash for Loop Over JSON Array Using jq
This file contains 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
#!/bin/bash | |
# https://www.starkandwayne.com/blog/bash-for-loop-over-json-array-using-jq/ | |
# how to run | |
# chmod u+x loop-over-json.sh | |
# ./loop-over-json.sh | |
sample='[{"name":"foo"},{"name":"bar"}]' | |
for row in $(echo "${sample}" | jq -r '.[] | @base64'); do | |
_jq() { | |
echo ${row} | base64 --decode | jq -r ${1} | |
} | |
echo $(_jq '.name') | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment