Skip to content

Instantly share code, notes, and snippets.

@unpluggedcoder
Created January 22, 2021 09:53
Show Gist options
  • Save unpluggedcoder/04fbf08fc81dbd6c0a49fd542faf52b1 to your computer and use it in GitHub Desktop.
Save unpluggedcoder/04fbf08fc81dbd6c0a49fd542faf52b1 to your computer and use it in GitHub Desktop.
for loop with jq in Bash
# 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