Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2722

【jq】bashでjson配列をループさせる

$
0
0
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" 参考 jq Manual (development version) looping through JSON array in shell script · GitHub bash - How to read complete line in 'for' loop with spaces - Ask Ubuntu

Viewing all articles
Browse latest Browse all 2722

Trending Articles