如何从空手道的响应数据中验证 1 json 中的所有项目是否可用

How to verify if all the items in 1 json is available from karate's response data

我有一个 JSON 文件,我正在阅读 Karate 特征文件,其中包含 ID,如下所示 temp.json

{
  112354,
  221344,
  126789,
  122333
}

在我的空手道功能文件中,我调用了一个 API,returns 数据库中所有可用的 ID。对此的反应很复杂json arrays。要从响应中检索一个 ID,我必须执行如下操作

company[0].department[0].project[0].id

response json structure
{
  "company": [
    {
      "department": [
         {
           "project": [
             {
               "id": 567436
             },
             {
               "id": 123456
             }
            ]
         }
       ]
    }
   ]
}


现在我想匹配 temp.json 中的所有 ID 在我通过调用 [=29 从空手道获得的 json 响应中可用=].它必须遍历所有数组以查看 ID 是否可用。在空手道中有什么方法可以做到这一点吗?

很可能你可以在一行中实现你想要的:

* def ids = [ 123, 234, 345 ]
* def response = [{ id: 123 }, { id: 234 }, { id: 345 }]
* match response..id == ids

所以请注意如何在 Json 路径中使用 ..

请查看这些其他答案以获取更多信息: