从 JSONPath 中的不同数组对象查询具有特定值的键

Query for key with specific value from different objects of array in JSONPath

{
  "dataObject": [
    {
      "id": 263626,
      "role": {
        "id": 12054,
        "name": "Edit",
        "description": ""
      },
      "resource": {
        "id": 5756,
        "type": "resource"
      }
    },
    {
      "id": 263364,
      "role": {
        "id": 12054,
        "name": "Edit",
        "description": ""
      },
      "resource": {
        "id": 5728,
        "type": "resource"
      }
    }
  ]
}

我有一个 JSON 对象,看起来像这样。我需要从具有 name:Edit 和 id:5756dataObject 中提取 json 对象。 如何使用 JSON 路径实现此目的? 试过 $..[?(@.name="Edit", @.id=5756)] 没用。

Java代码:

JsonPath.parse(json).read("$..[?(@.name='Edit'), (@.id=5756)]")

尝试使用父对象名称和逻辑运算符AND。结果路径将是

$..[?((@.resource.id == 5756) && (@.role.name == 'Edit'))].

我在 com.jayway.jsonpath:json-path:2.4.0

的单元测试中很有效
@Test
public void testParse() {
    String json = "{\n" +
            "  \"dataObject\": [\n" +
            "    {\n" +
            "      \"id\": 263626,\n" +
            "      \"role\": {\n" +
            "        \"id\": 12054,\n" +
            "        \"name\": \"Edit\",\n" +
            "        \"description\": \"\"\n" +
            "      },\n" +
            "      \"resource\": {\n" +
            "        \"id\": 5756,\n" +
            "        \"type\": \"resource\"\n" +
            "      }\n" +
            "    },\n" +
            "    {\n" +
            "      \"id\": 263364,\n" +
            "      \"role\": {\n" +
            "        \"id\": 12054,\n" +
            "        \"name\": \"Edit\",\n" +
            "        \"description\": \"\"\n" +
            "      },\n" +
            "      \"resource\": {\n" +
            "        \"id\": 5728,\n" +
            "        \"type\": \"resource\"\n" +
            "      }\n" +
            "    }\n" +
            "  ]\n" +
            "}";

    DocumentContext parse = JsonPath.parse(json);
    Object read = parse.read("$..[?((@.resource.id == 5756) && (@.role.name == 'Edit'))]");
    assertNotNull(read);
}