jq - windows examples

Created on 9 Jun 2014  路  13Comments  路  Source: stedolan/jq

Hi,

I am trying to run jq on an output from aws cli command but it does not work. i tried to run a simple example but it's not working as well. can you provide with some windows examples i can start play with?

Thanks

docs

Most helpful comment

@dandv The problem is the _shell_, not jq. The problem here is that the shell doesn't handle single quotes like a Unix shell: it passes the single quotes to jq, and since single quotes are not a normal part of a jq program, you get an error. I think we could add some rules to the parser to produce an error message that might help the user understand.

Anyways, jq . (no single quotes) works on Windows.

All 13 comments

whatever i use i get:
error: syntax error, unexpected INVALID_CHARACTER, expecting $end

do you have a windows example which can take an object like
{
"Timestamp": "2014-06-01T10:00:00Z",
"Maximum": 1,
"Unit": "None"
}
and create something like
"2014-06-01T10:00:00Z,1,"None"

it creates each value in a new row for me.

Thanks

It's all about the quoting:

C:\temp>jq -r ".Timestamp + \",\" + (.Maximum | tostring) + \",\" +

.Unit"
{
"Timestamp": "2014-06-01T10:00:00Z",
"Maximum": 1,
"Unit": "None"
}
2014-06-01T10:00:00Z,1,None

The cmd.exe shell is not like a Unix shell...

I've updated the manual in master; I'll update the site later today.

Can we have a simple _and complete_ example to pretty print a json file on Windows?

One really should not have to spend more than 5 minutes reading through the docs and trying to figure out how in the world to accomplish the simplest possible JSON task, pretty-printing a .json file, without getting

error: syntax error, unexpected INVALID_CHARACTER, expecting $end

at every attempt.

jq '.' < file.json fails. type file.json | jq '.' fails etc. Highly frustrating.

yeah, for simple tasks like that it's easier to just use jsonlint (and grep)

@dandv The problem is the _shell_, not jq. The problem here is that the shell doesn't handle single quotes like a Unix shell: it passes the single quotes to jq, and since single quotes are not a normal part of a jq program, you get an error. I think we could add some rules to the parser to produce an error message that might help the user understand.

Anyways, jq . (no single quotes) works on Windows.

There's now a Windows section in the FAQ. And there's a FAQ on this topic.

It looks like even in powershell in windows you have to backslash the doublequotes...sometimes. Maybe powershell should be mentioned in the faq?

echo '"Hello"' | jq '. + \" world\"'

"Hello world"

Can't get this to work (it works for powershell in osx at least):

jq -n '\"Hello world!\"'

jq: error: syntax error, unexpected $end, expecting QQSTRING_TEXT or QQSTRING_INTERP_START or QQSTRING_END (Windows cmd shell quoting issues?) at <top-level>, line 1:
"Hello
jq: 1 compile error

@jszabo98 Windows doesn't use single quotes, and since you're escaping the double quotes, it's splitting on the space. Try jq -n "\"Hello world!\"" (which works for me).

Powershell uses both single quotes and double quotes. But somehow the double quotes sometimes get lost with external programs, even within single quotes.

@jszabo98 oh, that's because on Windows there's no proper argument vector, and programs have to do their own command-line parsing.

@jszabo98 Windows doesn't use single quotes, and since you're escaping the double quotes, it's splitting on the space. Try jq -n "\"Hello world!\"" (which works for me).

Sadly this doesn't work for me. Here is my code:
IF "%COMPANY_ID%"=="" curl -H "Authorization: Bearer %ACCESS_TOKEN%" -X GET https://api.company.com/vapid/companies | jq ".[] | select (.name=="\"My Company Name\"") | .[].id"

@nicowilliams do you have any ideas?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

geoffeg picture geoffeg  路  3Comments

lhunath picture lhunath  路  3Comments

neowulf picture neowulf  路  3Comments

tischwa picture tischwa  路  4Comments

kelchy picture kelchy  路  4Comments