I would like to feed jq a filter program for it to read from a file, such as this:
jq my-awesome-filter.jq whatever.json
or this:
jq -n my-awesome-filter.jq
Right now I'm sidestepping it with (using fish shell):
jq (cat my-awesome-filter.jq | tr -d "\n\r\t") whatever.json
and:
jq -n (cat my-awesome-filter.jq | tr -d "\n\r\t")
Would there be interest on being able to do this? Is there anything I can do to help?
There's a -f option for this. Supposing we used file extensions to decide whether a file has data or a jq program, what should jq do if invoked with multiple programs? And would positional order matter?
Oh, is there? In that case, I think it's probably alright. It probably should be specified on the man page.
As an aside, it would be cool if we could invoke jq with multiple programs and it piped the input through all of them, such that, for example:
jq -fpipe this.jq that.jq -- input.json
does the same as:
jq -f this.jq input.json | jq -f that.jq
although, perhaps, it might be useful if things defined on a file were available on the following ones.
+1
I have been doing
jq "$(cat this.jq that.jq)"' . | my_filter'
-f is perfect, but +1 for putting it in the man page. :-)
Most helpful comment
-fis perfect, but +1 for putting it in the man page. :-)