Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jq - windows examples #392

Closed
DBAranAce opened this issue Jun 9, 2014 · 14 comments
Closed

jq - windows examples #392

DBAranAce opened this issue Jun 9, 2014 · 14 comments
Assignees
Labels

Comments

@DBAranAce
Copy link

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

@DBAranAce
Copy link
Author

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

@DBAranAce
Copy link
Author

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

@nicowilliams
Copy link
Contributor

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...

@nicowilliams
Copy link
Contributor

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

@nicowilliams nicowilliams added this to the 1.5 release milestone Jun 9, 2014
@nicowilliams nicowilliams self-assigned this Jun 9, 2014
@nicowilliams nicowilliams removed this from the 1.5 release milestone Jun 10, 2014
@dandv
Copy link

dandv commented Aug 6, 2014

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.

@pannous
Copy link

pannous commented Aug 6, 2014

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

@nicowilliams
Copy link
Contributor

@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.

@pkoppstein
Copy link
Contributor

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

@jszabo98
Copy link

jszabo98 commented May 3, 2019

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

@nicowilliams
Copy link
Contributor

@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).

@jszabo98
Copy link

jszabo98 commented May 8, 2019

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

@nicowilliams
Copy link
Contributor

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

@Loizzus
Copy link

Loizzus commented Dec 18, 2019

@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?

@ClaudiaR6
Copy link

¿Podemos tener un ejemplo simple y completo para imprimir bastante un archivo json en Windows?

Uno realmente no debería tener que pasar más de 5 minutos leyendo los documentos y tratando de descubrir cómo en el mundo realizar la tarea JSON más simple posible, imprimir un archivo .json, sin obtener

error: error de sintaxis, INVALID_CHARACTER inesperado, esperando $end

en cada intento.

jq '.' < file.jsonfalla type file.json | jq '.'falla, etc. Altamente frustrante.

type file.json | jq

A mi eso me sirvió Gracias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants