jq 脚本文件没有得到 key/value 对

jq script file not getting the key/value pair

我想将所有 jq 过滤器放在一个文本文件中,并使用 jq -L 选项来执行过滤器。但是,我无法让这个简单的东西工作。

在我的 sample2.json 文件中,我有:

{
        "a": 86,
        "b": 99
}

在我的 json2csv 文件中,我有:

.["a"]

当我这样做时:

cat sample.json | jq -L json2csv

输出的是整个sample.json文件,像这样:

但我希望输出只是 86 因为:

如何更改 json2csv 文件的内容,以便在输出中只能得到 86? 我正在使用 jq 1.6。谢谢!

改用jq -f json2csv

来自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.

将此与以下内容进行比较:

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