mardi 30 juin 2020

Karate: assert with conditional nesting on json

My API returns a response like below:

response = ''' { "value": [ "testvalue: "myvalue", "id": "12345", "child":[ { "testvalue": "child1value", "id": "568" "child": [] }, { "testvalue": "child2value", "id": "999" "child": [ { "testvalue": "child2.1value", "id": "100" "child": [] ] } ] ] } '''

My response could be nested at any child level. I basically enter an id as a param while hitting my API When params {"id":"100"} Where I get the above response which is nested at a child level. My use case is to validate and move ahead into the nested response based on a condition My API will always return one list but it could have nested child elements I want to validate something like: response = value[0]

if response.id == 100 then assert as match found If not then go inside the first child And perform the same if condition

I need to dig until I found the id matching as part of the entire response.

Is that something we could achieve with karate?

Aucun commentaire:

Enregistrer un commentaire