打印一个值然后将整个 json 文档转发到下一个过滤器的过滤器,例如 tee

filter that prints a value and then forwards the entire json document to the next filter, like tee

是否可以在过滤器中打印文档的部分内容,然后继续 select 进一步向下并稍后打印更多内容?

这是我想要的伪代码。

{
    "version":"1",
    "some":{
        "more":{
            "depth":"here"
        }
    }
}

select(.some.more.depth=="here") | tee .version | .some.more.depth

这将输出

"1"
"here"

我知道,在这种情况下,它可以与 .version, .some.more.depth 一起使用,但在更复杂的情况下,它更多的是在打印部分的同时处理文档。

https://jqplay.org/s/n7WjphEVf7

不只是在这种情况下,在任何情况下。这就是逗号运算符的作用和用途。它在同一上下文中运行两个表达式,并生成两者的所有输出。请记住,您始终可以使用括号,所以像

这样的做法是合法的
.a.b.c | (.d, .e.f | (.g, .h))

产生.a.b.c.d.a.b.c.e.f.g.a.b.c.e.f.h