Forum Discussion

NithyaTN's avatar
12 years ago

Using XQuery for verifying the JSON content in response xml

We need to verify the JSON content which is residing inside the tag called "JSON" in the response xml.
Sample format as follows:
<result>
<param name="json">{"response":{"Result":"SUCCESS"}}</param>
</result>

For example ,in the above response we just need to confirm is Result tag is returing SUCCESS or not.

We have tried using below code
<Result>
{
for $z in /result/param[@name='json']
return<param>{$z/text()}</param>
}
</Result

We could verify the whole json using
<Result>
<param>{"response":{"Result":"SUCCESS"}}param>
</Result>

But we would require to verify only SUCCESS in the above response.
Could anyone please help us on this?

1 Reply

  • SiKing's avatar
    SiKing
    Community Hero
    Grab the content from the XPath, and parse it like JSON. Something like this:

    def slurper = new groovy.json.JsonSlurper()
    def result = slurper.parseText(context.expand('${' + context.currentStep.name + '#Response//*:param[@name="json"]}'))
    assert result.response.Result.equals("SUCCESS")