LoginSignup
24

More than 5 years have passed since last update.

jqをWindowsマシンにインストールして使ってみる

Last updated at Posted at 2019-01-18

Macではよく使っていたjqを、Windowsマシンにインストールして使ってみたときのメモです。

jqインストール

オフィシャルからexeファイルをダウンロードしてお好みの場所に配置します。お好みで環境変数のPATHを通します。

>jq-win64.exe -V
jq-1.6

参考
Windows で JSONを整形する
https://kagasu.hatenablog.com/entry/20151223/1450829136

サンプルjsonを作ります

>type sample.json
[
  {
    "aa": [
      "bb",
      "cc"
    ],
    "dd": "ee",
    "ff": {
      "gg": "hh",
      "ii": "jj"
    }
  }
]

参考
JSON Pretty Linter Ver3
https://lab.syncer.jp/Tool/JSON-Viewer/

いろいろ試します

コマンドプロンプトでも、以下のように、馴染みのあるLinux風のjqの使い方ができそうです。

>type sample.json  | jq-win64.exe ".[]"
{
  "aa": [
    "bb",
    "cc"
  ],
  "dd": "ee",
  "ff": {
    "gg": "hh",
    "ii": "jj"
  }
}

とか、

>type sample.json  | jq-win64.exe ".[] | ."
{
  "aa": [
    "bb",
    "cc"
  ],
  "dd": "ee",
  "ff": {
    "gg": "hh",
    "ii": "jj"
  }
}

とか

>type sample.json  | jq-win64.exe ".[] | .aa"
[
  "bb",
  "cc"
]

とか。

typeのかわりにmoreコマンドでもよさそうです。

参考
パイプを使いコマンドの標準出力を他のコマンドの標準入力へ渡す
https://www.adminweb.jp/command/redirect/index6.html

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24