空手道:json 路径元素等于不起作用

Karate: json path element equals not working

我有这个功能:

Given path 'group/'
When method get
Then status 200
And match response.group[*].name contains [ 'group1' ] #Works
And match response.group[?(@.name == 'group1')].name contains [ 'group1' ] #Does not work

这是 group/ 端点的响应:

{
  "group": [
    {
      "name": "group1",
      "id": 1
    },
    {
      "name": "group2",
      "id": 2
    }
  ]
}

我收到这个错误:

groups.groups: groups.feature:35 - evaluation (js) failed: 'group1')].name contains [ 'group1' ], <eval>:1:8 Expected ; but found )
'group1')].name contains [ 'group1' ]
        ^ in <eval> at line number 1 at column number 8

我检查了 https://github.com/json-path/JsonPath#path-examples 中的语法,似乎没问题。

提前致谢。

已编辑:非工作表达式只是使问题简单的示例。实际上,我想从列表中获取整个组,这样我就可以比较其他字段,例如 id 并使用我无法与 contains:

一起使用的模糊匹配器
And match response.group[?(@.name == 'group1')][0] ==
"""
{
  "name": "group1",
  "id": #notnull
}
"""

是的,这是解析器的错误,LHS 上的括号混淆了它。但这很少见(在这种情况下是超级做作的)。执行两个步骤:

* def temp = $.group[?(@.name == 'group1')].name
* match temp contains [ 'group1' ]

欢迎针对文档或代码提交 PR,谢谢 ;)