groovy - Getting node from Json Response -


i have following json response:

 {     "0p0000g5zq":    [     {     "title": "pimco unconstrained bond inst",     "resourceid": "587723",     "publicationtime": "2013-03-07 14:13:00 -0600",     "type": "research",     "href": null,     "videothumbnail": null,     },     {     "title": "nontraditional bond 101",     "resourceid": "609234",     "publicationtime": "2013-08-27 06:00:00 -0500",     "authorname": "josh charney",     "type": "news"     "videothumbnail": null,     },     {     "title": "investors on move rates rise",     "resourceid": "607677",     "publicationtime": "2013-08-16 06:00:00 -0500",     "authorname": "christine benz",     "type": "video",     "subtype": "mstarvdvd",     "videothumbnail":     "http://im.mstar.com/im/videocenter/130814_flows_largethumb.jpg",     }     ],     "0p0000pzcb": [],     "0p00002pyr":    [     {     "title": "fpa new income",     "resourceid": "578826",     "publicationtime": "2012-12-26 00:00:00 -0600",     "authorname": "sarah bush",     "type": "research",     "href": null,     "videothumbnail": null,     },     {     "title": "fpa new income, inc. 2nd quarter 2013 conference call",     "resourceid": "bwiprem_20130719005736",     "publicationtime": "2013-07-19 12:32:00 -0500",     "source": "business wire",     "type": "news",     "subtype": "bwiprembwiprem",     "videothumbnail": null,     "authorthumbnail": null     }      ]     } 

i need print following nodes response ex:"0p0000g5zq", "0p0000pzcb", "0p00002pyr" etc , within each of these nodes need assert if "title" node present. response nodes:"0p0000g5zq", "0p0000pzcb", "0p00002pyr" keep on changing depending on service running need obtain response , not hardcode it. have in script assertion in soapui.

i have tried use json slurper nodes:"0p0000g5zq", "0p0000pzcb", "0p00002pyr" etc follows:

import com.eviware.soapui.support.xmlholder import org.apache.commons.lang.stringutils import groovy.json.jsonslurper   def holder = new xmlholder(messageexchange.responsecontentasxml) def response = messageexchange.response.responsecontent log.info response  def slurper = new jsonslurper() def json = slurper.parsetext(response) log.info json.each 

but returns following info:null.

can provide me sample code this? thanks.

def slurp = new groovy.json.jsonslurper().parsetext(jsonstr) slurp.each{key, val ->     val.each{         assert "title" in it.keyset()     } } 

where jsonstr represents above json response in string. (enclosed in '''yourjson''')


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -