在unix管道中串联多个空jq

时间:2019-07-13 18:24:50

标签: json command-line jq

当我在jq中传递json时,我得到了正确的结果:

echo '{"foo":"bar"}' | jq
{
  "foo": "bar"
}

但是当我尝试再次将其传送到jq时,

echo '{"foo":"bar"}' | jq | jq

我收到以下消息

jq - commandline JSON processor [version 1.5]
Usage: jq [options] <jq filter> [file...]

    jq is a tool for processing JSON inputs, applying the
    given filter to its JSON text inputs and producing the
    filter's results as JSON on standard output.
    The simplest filter is ., which is the identity filter,
    copying jq's input to its output unmodified (except for
    formatting).
    For more advanced filters see the jq(1) manpage ("man jq")
    and/or https://stedolan.github.io/jq

    Some of the options include:
     -c     compact instead of pretty-printed output;
     -n     use `null` as the single input value;
     -e     set the exit status code based on the output;
     -s     read (slurp) all inputs into an array; apply filter to it;
     -r     output raw strings, not JSON texts;
     -R     read raw strings, not JSON texts;
     -C     colorize JSON;
     -M     monochrome (don't colorize JSON);
     -S     sort keys of objects on output;
     --tab  use tabs for indentation;
     --arg a v  set variable $a to value <v>;
     --argjson a v  set variable $a to JSON value <v>;
     --slurpfile a f    set variable $a to an array of JSON texts read from <f>;
    See the manpage for more options.

我该如何解决?

在某些情况下,这是针对某种自动化的,其中性能不是问题,因此,是否经过某些jq遍也没关系

1 个答案:

答案 0 :(得分:1)

我缺少.

echo '{"foo":"bar"}' | jq . | jq .

注意:尽管可以解决问题,但我不明白为什么。即使jq打印到标准输出,以下jq也无法从中读取。