json 使用变量的空手道获取响应

karate fetch response of json using variable

在我的回复json中,有一个日期字段每天都在变化。

这是我的 json:

{
    "data": {
        "0000164": {
            "2019-04-03": {
                "VALUE": 26
            }
        }
    },
    "status": 200
}

从json获取数据我正在使用命令:$.data.0000164.2019-04-03.OAK

但我想概括 case.I 将日期保存在变量中

示例:

* def date = '2019-04-03'
* def hotel = '0000164'

想通过用这些值替换酒店和日期字段来获取响应

$.data.hotel.date.OAK

您需要使用jsonPath :

* def date = '2019-04-03'
* def hotel = '0000164'
* def answer = karate.jsonPath(response, "$.data." + hotel + "." + date + ".OAK")