从JSON负载中提取多个字段

从JSON负载中提取多个字段,json,jq,Json,Jq,我有以下有效载荷 [ { "name": "ProductCostingBJF_v2.3.0", "commit": { }, "protection": { "enabled": true, "required_status_checks": { "enforcement_level": "off", "contexts": [] } } }, { "name": "

我有以下有效载荷

[
  {
    "name": "ProductCostingBJF_v2.3.0",
    "commit": {
    },
    "protection": {
      "enabled": true,
      "required_status_checks": {
        "enforcement_level": "off",
        "contexts": []
      }
    }
  },
  {
    "name": "master",
    "commit": {
    },
    "protection": {
      "enabled": true,
      "required_status_checks": {
        "enforcement_level": "off",
        "contexts": []
      }
    }
  }
]
你能帮我用jq语法把它拉出来并呈现出来吗

ProductCostingBJF_v2.3.0    true
master                      true
我得到了第一部分。。。我可以用计算机获取分支机构的名称

jq  -r .[].name

但是我不知道如何获得启用值。

您可以使用以下jq命令:

jq -r '.[]| "\(.name) \(.protection.enabled)"' a.json 
您可以通过管道将其连接到
,以获得对齐的输出:

jq -r '.[]| "\(.name) \(.protection.enabled)"' a.json | column -t
输出:

ProductCostingBJF_v2.3.0  true
master                    true

下面是使用连接行(
-j
)的替代语法:


[],[.] .[.]保护。像这样启用的。考虑使用字符串插值代替:<代码> \(.name)\(.Entry.Fabelt)绝对更好,因为它不需要显式运行<代码> toString 。从现在起我将使用它!谢谢你的提示!当场回答-这是非常感谢和提示如何获得在线是非常有帮助的
$ jq -j '.[] | .name, "\t", .protection.enabled, "\n"' payload.json 
ProductCostingBJF_v2.3.0    true
master  true