Last active
June 17, 2025 17:04
-
-
Save IAmStoxe/a36b6f043819fad1821e7cfd7e903a5b to your computer and use it in GitHub Desktop.
This example shows you how to utilize jq to loop bash script through an array of JSON values.
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
jsonData='[{"name": "name#1","value": "value#1"},{"name": "name#2","value": "value#2"}]' | |
for row in $(echo "${jsonData}" | jq -r '.[] | @base64'); do | |
_jq() { | |
echo "${row}" | base64 --decode | jq -r "${1}" | |
} | |
# OPTIONAL | |
# Set each property of the row to a variable | |
name=$(_jq '.name') | |
value=$(_jq '.value') | |
# Utilize your variables | |
echo "$name = $value" | |
done | |
# $ stoxe@box:~$ ./loop-json-test.sh | |
# name#1 = value#1\ | |
# name#2 = value#2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for row in $(jq -r -c '.[]' ./json.json); do a=$(echo $row | jq -r '.a') b=$(echo $row | jq -r '.b') b=$(echo $row | jq -r '.c') echo $a echo $b echo $c done