JQ中竖管和并列有什么区别?

Dim*_*ims 3 json jq syntax

我的程序返回JSONstdout它是一个对象operations字段,其中包含操作的列表。每个操作都包含包含字段的id字段,例如:

{
    "operations": [
        {
            "id": "694ef895-793f4631-41103e8-8ab59e66",
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用jq.

如果我在写

jq '.operations | .[] | .id'
Run Code Online (Sandbox Code Playgroud)

它有效,如果我正在编写

jq '.operations | .[].id'
Run Code Online (Sandbox Code Playgroud)

它也有效。

即并列与|此处相同。

但是如果我写

jq '.operations.[].id'
Run Code Online (Sandbox Code Playgroud)

它失败并显示消息

jq:错误:语法错误,意外的“[”,期待 FORMAT 或 QQSTRING_START(Unix shell 引用问题?),第 1 行:.operations.[].id jq:1 编译错误

为什么以及如何解决?

dir*_*rkt 5

只要您只是比较.foo.barand |,就没有区别,正如手册页在“基本过滤器”下所说:

形式的过滤器.foo.bar等效于.foo|.bar.

是的,你需要.operations[].id在你的情况下。