Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
23
Help us understand the problem. What is going on with this article?
@amemolee

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

23
Help us understand the problem. What is going on with this article?
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
amemolee

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
23
Help us understand the problem. What is going on with this article?