Skip to content

Instantly share code, notes, and snippets.

@namp10010
Last active February 21, 2022 23:38
Show Gist options
  • Save namp10010/c7ef51abc1b2f7f5265634d250ad8aaa to your computer and use it in GitHub Desktop.
Save namp10010/c7ef51abc1b2f7f5265634d250ad8aaa to your computer and use it in GitHub Desktop.
Bash for Loop Over JSON Array Using jq
#!/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