SuperSingh
8 years agoContributor
How to extract & validate nodes from JSON which is part of XML response
I have response in XML format that contains metadata (which is in JSON).I need to extract the values from JSON and validate them. Can someone please help me with script to extract the JSON nodes . ...
- 8 years ago
Script assertion would be
import com.eviware.soapui.support.XmlHolder def holder = new XmlHolder(context.Response) def Metadata = holder["//*:Metadata"] log.info Metadata import groovy.json.JsonSlurper def slurper = new JsonSlurper() def json = slurper.parseText Metadata log.info(json.ID[0])
However your sample XML response seems to include invalid JSON so I changed the last line to
log.info(json.ID)
- 8 years agoNo worries.
Use below script:
https://github.com/nmrao/groovyScripts/blob/master/json/QueryJsonArray.groovy
use "log.info" instead of "println" in the above script.