0

我有以下 JSON 字符串。我需要一些帮助来编写一个 Jayway JsonPath 表达式来获取特定角色的受让人,比如“编辑”:

{
  "assignments": [
    {
      "role": {
        "label": "Editor",
        "id": "8bc3e27aafe310001fc933216b890910"
      },
      "assignees": [
        {
          "label": "user 1",
          "id": "bd76276f5e5344e4b27f8600c9000726"
        },
        {
          "label": "user 2",
          "id": "abbb210550af1017329208ee8632618c"
        }
      ]
    },
    {
      "role": {
        "label": "Owner",
        "id": "8bc3e27aafe310001fc932f0d928090f"
      },
      "assignees": [
        {
          "label": "user 3",
          "id": "3db5d9e1081e470bb98d5a3d15b67180"
        },
        {
          "label": "user 4",
          "id": "586e403c186c01521f763b5d4d0e6000"
        }
      ]
    },
    {
      "role": {
        "label": "Viewer",
        "id": "8bc3e27aafe310001fc9333ecccf0911"
      },
      "assignees": [
        {
          "label": "user 5",
          "id": "9bdfa0b60668100b619f393cfc282340"
        },
        {
          "label": "user 6",
          "id": "586e403c186c018f6c8d798c4e0e6a00"
        }
      ]
    }
  ]
}
4

2 回答 2

1

假设您使用的是 XPath 3.1,它是第一个提供对 JSON 数据的 XPath 访问的版本,您可以编写

assignments[?role?label = 'Editor']?assignees
于 2021-02-02T15:25:02.547 回答
0

我想出了答案

$.assignments[?(@.role.id=='8bc3e27aafe310001fc933216b890910')].assignees
于 2021-02-03T18:38:22.860 回答