Jq reference
Read a json file
Give a color.json
file with the following content:
[
{
"name": "red",
"value": "#ff0000"
},
{
"name": "green",
"value": "#008000"
},
{
"name": "blue",
"value": "#0000ff"
},
{
"name": "yellow",
"value": "#ffff00"
},
{
"name": "black",
"value": "#000000"
}
]
The following bash script will read the json array one by one
#!/usr/bin/env bash
JSON_FILE="color.json"
while read -r color; do
name=$(jq -r .name <<< "$color")
value=$(jq -r .value <<< "$color")
echo "Color $name has value as $value."
done < <(jq -c '.[]' $JSON_FILE)
Here is the sample output: