#jq コマンドと #shell の組み合わせで、 JSON 配列が空かどうかを条件判定する例


when Json array is empty

$ if [ $(echo '[]' | jq '. | length') -eq 0 ]; then echo empty; else echo non empty; fi
empty

when Json array is not empty

$ if [ $(echo '[1]' | jq '. | length') -eq 0 ]; then echo empty; else echo non empty; fi
non empty

Original by Github issue