Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

amemolee
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした