Example if i have response like this:
{
“id”: 11,
“name”: “Brenda”,
“username”: “brenda21”,
“email”: “brenda.test@mail.com”
}
And I want to verify if the id data-type is integer and name data-type is String.
Is there any keyword or script I can use to check that?
You can use JSON Schema technology for verifying JSON instances against schema. For example, see
However, this would require seasoned skill of programming — not very easy.
The simplest but non-extensible example:
import groovy.json.JsonSlurper
def json = """
{
"id": 11,
"name": "Brenda",
"username": "brenda21",
"email": "brenda.test@mail.com"
}
"""
JsonSlurper slurper = new JsonSlurper()
def obj = slurper.parseText(json)
assert obj['id'] instanceof Integer
assert obj['name'] instanceof String
Verification using JSON Schema is much more extensible.