4
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2021-05-16

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"

参考

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0