jq
jsonデータを良い感じに整形してCLIで表示してくれるやつ
curlコマンドとかと合わせて使うことが多い
$ curl 'http://hogehoge.com' | jq
$ http --print="b" http://hogehoge.com | jq
docs
github
#WIP
こういうフォーマット
$ jq '<ここにjq用のコード>'
jq内でパイプができる
$ jq '<jq用のコード1> | <jq用のコード2> | <jq用のコード3>'
いろいろ
https://dev.classmethod.jp/tool/jq-manual-japanese-translation-roughly/
docs
mapとかある ref
unique
jqのreduce関数
フォーマットの例 ref
reduce "元データ" as "アキュムレータ" ("出力形式"; . + "出力フォーマット")
出力フォーマットの前の+は、結合を意味するだけで、必ずしもreduceとセットのformatという意味ではない
例
reduce .[] as $item({}; . + {($item.id) : $item.data} )
https://dev.classmethod.jp/tool/road-to-jq-master-journeyman/
https://dev.classmethod.jp/tool/jq-manual-japanese-translation-roughly/
filterっぽいこと
mapとselectで頑張るなど
map(select(.hoge != null))
#??
これどうやってpipeにするん?
なんかの処理 | reduceとしたい
配列系
add
連結する
2つのファイルのjsonをmergeすることもできる ref
$ jq -s add hoge.json fuga.json
関連
https://qiita.com/manabuishiirb/items/aea10785a2daf5832c92
jq ispiredなツールたち
xml、yamlを整形する、など
書籍がある
『jqハンドブック―NetOps/DevOps必携のJSONパーザ』
https://www.amazon.co.jp/dp/4877834915
参考
jq コマンドを使う日常のご紹介 - Qiita
良い感じの整形の仕方参考
https://itchyny.hatenablog.com/entry/2019/08/26/090000
https://m-hiyama.hatenablog.com/entry/2022/12/05/122205