Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run jq from gitbash in windows?

Tags:

bash

git-bash

jq

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.

like image 684
DotNetDeveloper Avatar asked Dec 29 '18 07:12

DotNetDeveloper


People also ask

Does jq work on Windows?

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.

What is jq in bash?

jq command is used not only for reading JSON data but also to display data by removing the particular key. The following command will print all key values of Students. json file by excluding batch key. map and del function are used in jq command to do the task.


1 Answers

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 } 
like image 50
VonC Avatar answered Sep 20 '22 14:09

VonC