Begineer
Begineer

Reputation: 43

Karate scenario for array object in Rest JSON output

I have an output of get operation like :

[ { "field1": "123", "field2": [ "10008" ], "field3": "ABC", "field4": [ "XYZ" ], }]

Now I want to match the filed 4 output in the feature file. I have tried options like:

When method GET Then status 200 And match $response.field4[*] contains ['XYZ']

but I am not getting the desired results and getting Karateexception. Can anyone guide what i am doing wrong and how to match the output of array fields.

Upvotes: 1

Views: 43

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Look at your JSON structure carefully please:

* def response = [ { "field1": "123", "field2": [ "10008" ], "field3": "ABC", "field4": [ "XYZ" ] } ]
* match response[0].field4 contains 'XYZ'

Upvotes: 1

Related Questions