Edited at

bashでjqを使ってJSONの配列をループさせる

More than 1 year has passed since last update.


list.json

[

{
"key": "k1",
"val": "v1"
},
{
"key": "k2",
"val": "v2"
}
]

#!/bin/bash

json=$(cat list.json)
len=$(echo $json | jq length)
for i in $( seq 0 $(($len - 1)) ); do
row=$(echo $json | jq .[$i])
done


参考

bashでjqを使ってJSONのオブジェクトをループさせる