How do I validate in karate that a json attribute is returned as some string?

Viewed 200

In Karate tests, I'd like to evaluate whether an attribute returned in json response is of string type. Below is what am doing:

* def abc = response.results.abc
Then match abc == "#string?"

Below is the response am getting:

actual: 'lion', expected: '#string?', reason: did not evaluate to 'true'

Please let me know where I am wrong. Thanks.

1 Answers

You are overcomplicating it: https://github.com/karatelabs/karate#schema-validation

* def response = { abc: 'foo' }
* match response.abc == '#string'

It is recommended you match JSON objects all at once, your tests will be more crisp.

* match response == { abc: '#string' }
Related