简体   繁体   中英

jq script file not getting the key/value pair

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM