Jq: Providing jq filter program from file?

Created on 15 Feb 2014  路  4Comments  路  Source: stedolan/jq

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?

support

Most helpful comment

-f is perfect, but +1 for putting it in the man page. :-)

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neowulf picture neowulf  路  3Comments

lhunath picture lhunath  路  3Comments

kelchy picture kelchy  路  4Comments

rclod picture rclod  路  4Comments

thelonious picture thelonious  路  4Comments