jq-web
jq-web copied to clipboard
Add jq options
Hi,
would be possible to add also the options via the jq function like jq(
Thanks! :)
PS: here is what we are building with your library https://github.com/zalando-incubator/bro-q
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 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
Have you tried this?
function getJq(jsonInput, filter = '.') {
- return jq(JSON.parse(jsonInput), filter);
+ return jq.raw(jsonInput, filter);
}
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 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 :)
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