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

Add jq options #9

Open
mrandi opened this issue Aug 1, 2018 · 6 comments
Open

Add jq options #9

mrandi opened this issue Aug 1, 2018 · 6 comments

Comments

@mrandi
Copy link

mrandi commented Aug 1, 2018

Hi,

would be possible to add also the options via the jq function like jq(, , )?
we will need it for example for the option "-r"
image

Thanks! :)

PS: here is what we are building with your library https://github.com/zalando-incubator/bro-q

@fiatjaf
Copy link
Owner

fiatjaf commented Aug 1, 2018

Although it is already possible to call jq with arguments (I just don't document it because it doesn't work for most arguments) I believe your case will be nicely served by jq.raw(). Have you seen it?

@mrandi
Copy link
Author

mrandi commented Aug 1, 2018

@fiatjaf thx for the fast reply!
I actually saw it in your test and tried to use it, but I kind of failed.

Wanted to have it here: https://github.com/zalando-incubator/bro-q/blob/master/src/ts/background.js#L4

@fiatjaf
Copy link
Owner

fiatjaf commented Aug 1, 2018

Have you tried this?

 function getJq(jsonInput, filter = '.') {
-    return jq(JSON.parse(jsonInput), filter);
+    return jq.raw(jsonInput, filter);
 }

@fiatjaf
Copy link
Owner

fiatjaf commented Aug 1, 2018

Actually, since your case doesn't need synchronous application of the function, you should use jq.promised.raw().then(...) instead, to prevent stupid errors.

@mrandi
Copy link
Author

mrandi commented Aug 1, 2018

@fiatjaf I thought I did but I will try again, maybe I have some other issues

Thanks also for the tipp with promised, this was an hackweek project and I'm actually a java backend dev trying to get into something new :)

@romaninozemtsev
Copy link

romaninozemtsev commented Dec 8, 2020

from looking at generated code, the third parameter is for options.
like
jq.promised.raw(jsonInput, jqExpr, ['--raw-output'])

but it's "sticky", once applied it somehow stays there. so calling next time with
jq.promised.raw(jsonInput, jqExpr) will still print row output.

example

window.jq.raw('{"a":"b\\nc"}','.a', [])
""b\nc""
window.jq.raw('{"a":"b\\nc"}','.a', ["--raw-output"])
"b
c"
window.jq.raw('{"a":"b\\nc"}','.a', [])
"b

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

No branches or pull requests

3 participants