jq
の-c
オプションを使うことで、シンプルにループ処理が可能。
--compact-output / -c:
By default, jq pretty-prints JSON output. Using this option will result in more compact output by instead putting each JSON object on a single line.
array.json
$ JSON='
[
{
"name": "JSON",
"good": true
},
{
"name": "XML",
"good": false
}
]
'
IFS=$'\n'; for item in $(echo $JSON | jq -c '.[]'); do
echo $item | jq .name
done
# "JSON"
# "XML"