Reputation: 57
In my response json, there is a field of date which is changed as per day.
Here is my json:
{
"data": {
"0000164": {
"2019-04-03": {
"VALUE": 26
}
}
},
"status": 200
}
to fetch data from json i am using command :$.data.0000164.2019-04-03.OAK
but i want to generalise the case.I have the date saved in a variable
Example:
* def date = '2019-04-03'
* def hotel = '0000164'
want to fetch response by replacing hotel and date field with these values
$.data.hotel.date.OAK
Upvotes: 1
Views: 310
Reputation: 1090
You need to use jsonPath : https://stackoverflow.com/a/50855425/10791639
* def date = '2019-04-03'
* def hotel = '0000164'
* def answer = karate.jsonPath(response, "$.data." + hotel + "." + date + ".OAK")
Upvotes: 2