#jq コマンドでオブジェクトの配列から key の value で検索絞り込みする例


オブジェクトの配列から検索する場合

map と select を組み合わせて使う

$ echo '[{"answer": "yes"} , { "answer" : "no"}]' | jq 'map(select(.answer == "yes"))'
[
  {
    "answer": "yes"
  }
]

フラットな複数個以上のJSONから検索する場合

select だけで良い

$ echo '{"answer": "yes"} { "answer" : "no"}' | jq 'select(.answer == "yes")'
{
  "answer": "yes"
}

Original by Github issue