I would like to put all jq filters inside a text file and use the jq -L
option to execute the filters. However, I can’t get this simple thing working.
Inside my sample2.json
file, I have:
{ "a": 86, "b": 99 }
Inside my json2csv
file, I have:
.["a"]
When I do:
cat sample.json | jq -L json2csv
The output is the whole sample.json file, like this:
but I would expect the output is only 86
because:
How do I change the content of the json2csv
file so I can only get the 86
in the output?
I am using jq 1.6. Thanks!
Advertisement
Answer
Use jq -f json2csv
instead.
From man jq
:
-Ldirectory / -L directory:
Prepend directory to the search list for modules. If this option is used then no builtin search list is used. See the section on modules below.
Compare this to:
-f filename / –from-file filename:
Read filter from the file rather than from a command line, like awk´s -f option. You can also use # to make comments.