How to validate the response of a JSON attribute when key is number in Karate?

Viewed 187
  • def payload = {"1":{"clientName":"Peter Thomas"}, "2":{"clientName": "Karate Framework"}}

I need to find the path of clientName attribute and validate the values of it.

I tried * match payload.1.clientName == 'Peter Thomas', but it is throwing an error?

1 Answers

This works for me fine on Karate 1.0.1

* def payload = {"1":{"clientName":"Peter Thomas"}, "2":{"clientName": "Karate Framework"}}
* match payload.1.clientName == 'Peter Thomas'

Maybe you are on an old version. Please upgrade. The below may work for you - note that the "1" in the original payload is a string:

* match payload['1'].clientName == 'Peter Thomas'
Related