Forum Discussion

MauraR's avatar
MauraR
Occasional Contributor
12 years ago

[Resolved] help in asserting json response

Hello,
Can anyone please help me how I can assert the following json response?

{"2709": {
"id": 2709,
"status": "-1",
"comment": "",
"summary": "test summary"
}}

1. I need to assert that the value in "2709" is not null - this gets generated every time I send a POST. This value can be from 4 digits or more
2. I also need to assert that all fields are not empty - i.e. id, status, comment, and summary.

This is what I have started with, but I can't get the fields that I need to assert

import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def json = slurper.parseText response

Thanks,
MR
  • We normally don't provide support for Groovy scripts, but this is a quick fix:

    def innerMap = json[json.keySet().iterator().next()]
    def id = innerMap.id

    ... then you can assert the value of id

    Best regards,
    Manne Fagerlind
    SmartBear Stockholm