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

Providing jq filter program from file? #293

Closed
ghost opened this issue Feb 15, 2014 · 4 comments
Closed

Providing jq filter program from file? #293

ghost opened this issue Feb 15, 2014 · 4 comments
Labels

Comments

@ghost
Copy link

ghost commented Feb 15, 2014

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?

@nicowilliams
Copy link
Contributor

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?

@ghost
Copy link
Author

ghost commented Feb 15, 2014

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.

@JonathanAnderson
Copy link

+1

I have been doing

jq "$(cat this.jq that.jq)"' . | my_filter'

@timshadel
Copy link

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

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

No branches or pull requests

4 participants