Jsonpath:无法使用表达式获取所需的值

Jsonpath: can not get the needed value using expressions

这是例子JSON

{
  "customerId": 0,
  "authorizedCustomerIds": [
    0
  ],
  "creativeVersionId": 0,
  "description": "string",
  "version": "string",
  "duration": 0,
  "frameRate": 0,
  "previewImage": "string",
  "previewVideo": "string",
  "renderScript": "string",
  "renderScriptType": "string",
  "elements": [
    {
      "id": 0,
      "type": "IMAGE",
      "name": "string1",
      "parentId": 0,
      "presetId": 0,
      "properties": [
        {
          "name": "string",
          "value": {},
          "type": "ALPHABETIC",
          "producesVideo": true,
          "renderScriptId": "string"
        }
      ]
    },
    {
      "id": 1,
      "type": "TEXT",
      "name": "string2",
      "parentId": 0,
      "presetId": 0,
      "properties": [
        {
          "name": "string",
          "value": {},
          "type": "ALPHABETIC",
          "producesVideo": false,
          "renderScriptId": "string"
        }
      ]
    }
  ],
  "globalElements": [
    {
      "id": 0,
      "disabled": true
    }
  ],
  "shots": [
    {
      "name": "string",
      "displayOrder": 0,
      "startFrame": 0,
      "duration": 0,
      "thumbnailFrame": 0,
      "elements": [
        {
          "id": 0,
          "disabled": true
        }
      ]
    }
  ],
  "sizes": [
    {
      "name": "string",
      "displayOrder": 0,
      "main": true,
      "width": 0,
      "height": 0,
      "properties": [
        {
          "templateElementId": 0,
          "propertyName": "string",
          "linked": true,
          "value": {}
        }
      ]
    }
  ]
}

我需要获取类型为 TEXT 且属性“producesVideo”为 false 的元素名称。

我试过这种方法,但是不行

$..elements[?(@.type == 'TEXT' && @.properties[?(@.producesVideo == false)])].name

那我就放心提取路径了

.extract().path(); 

使用 findfindAll 条件

您使用的是什么 JSONPath 实现?对于该文档和 JSONPath 表达式,一些实现,例如jayway Java and jsoncons C++,将return值结果

[
   "string2"
]

或路径结果

[
   "$['elements'][1]['name']"
]

其他实现,例如Goessner Javascript,无法使用子过滤器消化过滤器表达式。克里斯托夫伯格默 JSONPath Comparison covers that case here.

使用放心的 findfindAll 表达式,jsonpath 应该是这样的:

.extract().path("elements.findAll{it.type == 'TEXT' && it.properties.find{it.producesVideo == false}}.name");