웹개발/시리얼통신

윈도우에 jq(JSON Parser) 설치

수제개발자 2019. 4. 16. 15:17

curl 명령어를 간략하기 하기 위해 json parser를 설치하려고 보니

윈도우는 어떻게 하라는지 검색해도 나오질 않았다.

jq 공식페이지에 chocolatey라는걸 설치해서 실행하라는 걸 잘 읽지 않았다.

 

jq 다운로드 링크

https://stedolan.github.io/jq/download/

 

Download jq

Download jq jq is written in C and has no runtime dependencies, so it should be possible to build it for nearly any platform. Prebuilt binaries are available for Linux, OS X and Windows. The binaries should just run, but on OS X and Linux you may need to m

stedolan.github.io

윈도우는 Chocolatey를 사용해 chocolatey install jq라는 명령어로 설치하라고 한다.

 

Chocolatey NuGet이라는 단어를 클릭하면

여러 터미널로 설치하는 법이 나온다. cmd로 설치하려면 관리자 권한으로 cmd를 실행해서

아래 명령어를 복붙한다.

 

https://chocolatey.org/install

 

Installation

That's it! All you need is choco.exe (that you get from the installation scripts) and you are good to go! No Visual Studio required. Chocolatey installs in seconds. You are just a few steps from running choco right now! With PowerShell, there is an additio

chocolatey.org

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

입력후 실행하면 설치가 진행된다.

 

choco를 설치한후 choco install jq 라는 명령어를 실행한다.

jq 윈도우용 실행파일은 미리 받아둔다.

경로는 상관없나 모르겠는데 나는 cmd실행경로에 두었다.

 

다음과 같이 나오면 설치된 것이다.

 

이제 jq를 통해 원하는 json 값을 가져오도록 한다.

 

curl -X GET https://api.github.com/repos/유저이름/저장소이름/contents/파일이름|jq .제이슨키이름

 

파일이름 뒤에 \ + shift한 | 이다.

jq다음에 한칸띄우로 .찍은뒤 리턴될 JSON중 원하는 key이름을 쓰면 value를 리턴한다.

아래에서는 sha라는 키값을 불러왔다.

키 값이 정상적으로 리턴되었다.