#author("2024-05-03T07:12:10+00:00","default:hotate","hotate") #author("2024-05-03T07:13:13+00:00","default:hotate","hotate") #contents &tag(JSON,コマンド); * [[コマンド]] [#oe0f2085] - [[jq - stedolan.github.io>https://stedolan.github.io/jq/]] jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text. - [[jq コマンドを使う日常のご紹介 - Qiita>https://qiita.com/takeshinoda@github/items/2dec7a72930ec1f658af]] 別のコマンドに流すときはダブルクォートが邪魔ですね。-r オプションで消えます。 - [[非JSONの文字列が含まれるファイルに対してjqを使いたい - 理系学生日記>https://kiririmode.hatenablog.jp/entry/20190901/1567302386]] 上記のようなケースにおいては、ぼくは以下のように jq -R 'fromjson?' 一度通すようにしています。 - [[jqコマンドでJSONを操作・分析する>https://zenn.dev/oreo2990/articles/49a20a09517d90]] (2022/10/24) 配列の要素を取得する場合は、'.配列の要素名[]'で取得できます。 cat people.json | jq '.results[]' - [[とほほのjq入門 - とほほのWWW入門>https://www.tohoho-web.com/ex/jq.html#options-output]] JSON の中から、age が 40 以下などの条件を指定して取り出すこともできます。 $ cat sample.json | jq -c '.users[] | select(.age <= 40)' * 関連 [#t86b776b] - [[JSON]]