如何在Windows中从gitbash运行jq? [英] How to run jq from gitbash in windows?

查看:497
本文介绍了如何在Windows中从gitbash运行jq?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows中有gitbash.我正在尝试运行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

意图:我想使用jq解析json.

Intention: I want to use jq to parse json.

推荐答案

使用 github.com/stedolan/jq/releases中的jq-win64.exe ,我知道了

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
}

它确实可以工作,但是它取决于您要解析的json文档.
如果该json文档格式不正确,则会生成您看到的错误.

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.

在bash会话中,您可以定义(或添加到~/.bashrc)别名:

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

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

那样,您无需使用./jq,而直接使用jq.

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

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

就我而言:

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

这篇关于如何在Windows中从gitbash运行jq?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆