jq-web icon indicating copy to clipboard operation
jq-web copied to clipboard

Add jq options

Open mrandi opened this issue 6 years ago • 6 comments

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

mrandi avatar Aug 01 '18 10:08 mrandi

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?

fiatjaf avatar Aug 01 '18 11:08 fiatjaf

@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

mrandi avatar Aug 01 '18 15:08 mrandi

Have you tried this?

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

fiatjaf avatar Aug 01 '18 16:08 fiatjaf

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

fiatjaf avatar Aug 01 '18 16:08 fiatjaf

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

mrandi avatar Aug 01 '18 20:08 mrandi

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

romaninozemtsev avatar Dec 08 '20 07:12 romaninozemtsev