使用空手道在 JsonPath 的过滤器部分中使用字符串占位符进行表达式

Expression with String placeholder in the filter part of JsonPath using karate

我正在尝试使用 JSON 路径过滤我的响应,其中一个条件使用变量中的值,但我无法正确映射变量,因此我的过滤器无法正常工作。

响应示例 JSON:

{
   "response":[
      {
         "id":"1234",
         "confirmationCode":"abcd"
      }
   ]
}

我在下面的脚本中使用变量 'code':

* def Code = 'abcd'
* def value = karate.jsonPath($.response[?(@.confirmationCode == ' + Code +')])

请仔细阅读文档:

* def value = karate.jsonPath(response, "$.response[?(@.confirmationCode=='" + Code + "')]")