How to run jq from gitbash in windows?

I have gitbash in Windows. I am trying to run jq but its giving me error.

$ ./jq-win64.exe
jq
parse error: Invalid numeric literal at line 2, column 0

Intention: I want to use jq to parse json.

111667 次浏览

Using jq-win64.exe from github.com/stedolan/jq/releases, I get

vonc@voncav MINGW64 /d/prgs/dl
$ ./jq-win64.exe --version
jq-1.6


vonc@voncav MINGW64 /d/prgs/dl
$ echo '{"foo": 0}' | ./jq-win64.exe .
{
"foo": 0
}

So it does work, but it then depends on the json document you are parsing with it.
If that json document is not well-formed, that would generate the error you see.

In your bash session, you can define (or add to your ~/.bashrc) an alias:

alias jq=/path/to/jq-win64.exe

That way, you don't need to use ./jq, but directly jq.

$ echo '{"foo": 0}' | jq

In my case:

vonc@voncav:/$ alias jq=/mnt/d/dwnl/jq-win64.exe
vonc@voncav:/$ echo '{"foo": 0}' | jq
{
"foo": 0
}

I just downloaded the binary to %HOMEPATH%/bin/jq-win64 and it worked right away via jq

I hate answers that say you need another to use another tool to download, but using https://chocolatey.org/ made this incredibly simple for me.

From an elevated command-prompt, run:

choco install jq

jq magically works from bash going forward.

Instead of using chocolatey (with elevated rights) you could also use scoop.sh:

scoop install jq

Easiest solution and always latest version:


run this curl in your gitbash:

curl -L -o /usr/bin/jq.exe https://github.com/stedolan/jq/releases/latest/download/jq-win64.exe

or manually save the jq-win64.exe in link above as jq.exe to your /usr/bin (which is in your git bash installation folder)

(if you are behind a proxy add the -x proxyhost:port)

enter image description here

Below steps worked for me in git bash on windows 10

curl -L -o jq-win64.exe https://github.com/stedolan/jq/releases/latest/download/jq-win64.exe


export PATH=$PATH:"/C/Users/devops/Downloads/jq-win64.exe


jq --version


jq-1.6


In my case, I have fixed it in Windows10 while practicing a scenario of "Techworld with Nana" course, as per the below steps:

1) open "cmd" prompt (Run as administrator)

2) curl -L -o /usr/bin/jq-win64.exe Download it here

3) You can add C:\Program Files\Git\usr\bin path to your environment variables. If you follow this step, ignore the below steps.

[OR]

3) Go to the directory where jq is downloaded: C:\Program Files\Git\usr\bin and copy the file to C:\ drive

4) Add the path C:\ to "path" environment variable. This PC-->Properties-->Advanced system settings --> Environment Variables -->Edit-->New. Then add the path (where you copied jq.exe, i.e., C:) and Save it.

5) Now open a new "cmd" prompt, jq --version

For windows Powershell && cmd

Download executable -> jq 1+ executables for 64-bit

Create folder in Program Files -> JQ

Copy .exe into program folder

Set environment variable to that folder

Restart terminal

Set alias

 Set-Alias -Name jq -Value .\jq-win64.exe

Run command

 echo '{"foo": 0}' | jq

Output

 {
"foo": 0
}

enjoy!