Scala - Gatling - JsonPath - 检查是否存在具有特定值的对象

Scala - Gatling - JsonPath - Check if object with specific value exist

我有一个像这样的 jsonpath 响应:

{
  "pageable": {
    "currentPage": 1,
    "totalPages": 1,
    "pageSize": 20,
    "last": true,
    "first": true
  },
  "sort": {
    "orders": [],
    "sorted": false,
    "unsorted": true,
    "empty": true
  },
  "totalElements": 6,
  "data": [
    {
      "id": 1,
      "roleName": "test1",
      "userCount": 5
    },
    {
      "id": 2,
      "roleName": "test2",
      "userCount": 5
    }
  ]
}

我想检查 id == 1 的数据是否存在。 我尝试了一些组合,例如:

checks ::= jsonPath("$..data.*[?(@.id=='1')]").exists
checks ::= jsonPath("$.data.*[?(@.id=='1')]").exists
checks ::= jsonPath("$..data[?(@.id=='1')]..id").exists
checks ::= jsonPath("$..data[?(@.id=='1')].id").exists
checks ::= jsonPath("$.data[?(@.id=='1')].id").exists

但是没有路径有效,我收到错误消息:

jsonPath($..data..*[?(@.id=='1')]).find.exists, found nothing 

有什么想法吗?

而不是尝试使用 JsonPath whose syntax is unclear and lacks a standard, you should try JMESPath instead, that Gatling supports as well

jmesPath("data[?id == `1`]")