raj N ish Ku M ar raj N ish Ku M ar - 1 year ago 162
JSON Question

Soapui how to extract a certain value form json response

I am trying to extract value of

, but not able to do that.

Please find below details.

Groovy Script which I am working is :

import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
log.info response

def slurper = new JsonSlurper()
def json = slurper.parseText response
log.info json
log.info json.New England Schools__NE Schools$.dsId

but getting below error
enter image description here

My json response is below please help
also want to extract value of ZIP

"New England Schools__NE Schools$": {
"dsId": "ds_608",
"type": "Account",
"numericCols": [
"Count Free Lunch",
"Count Reduced Lunch",
"Total Lunch Pgm",
"Total Students",
"Grade 1",
"Grade 2",
"Grade 3",
"Grade 4",
"Grade 5",
"Grade 6",
"Grade 7",
"Grade 8",
"Grade 9",
"Grade 10",
"Grade 11",
"Grade 12"
"data": null,
"AggNumericData": [
"ZIP": 19949795,
"Count Free Lunch": 263596,
"Count Reduced Lunch": 71799,
"Total Lunch Pgm": 331987,
"Total Students": 1796594,
"PreKindergarten": 36553,
"Kindergarten": 151898,
"Grade 1": 164370,
"Grade 2": 169418,
"Grade 3": 173748,
"Grade 4": 175505,
"Grade 5": 179357,
"Grade 6": 177978,
"Grade 7": 174655,
"Grade 8": 170192,
"Grade 9": 178423,
"Grade 10": 162045,
"Grade 11": 147564,
"Grade 12": 133368
"MinMax": [],
"dsData": "Account Id#%#Territory#%#District#%#Area#%#Region#%#objname#%#~ID~#%#~Lat-Lon ...}

Rao Rao

You got very trivial error.

Couple of things:

  • The property has got space characters : so it needs to be enclosed within quotes
  • There is $ as well which needs to be escaped.

Here is the statement which can retrieve the required value of dsId

Change your last statement from :

log.info json.New England Schools__NE Schools$.dsId


log.info json."New England Schools__NE Schools\$".dsId

Hope this helps.


Just noticed that you wanted to extract ZIP value which is happen to be the property of first element in the array AggNumericData. Earlier, this question in your post was not visible or I overlooked. So updating the same in my answer.

Here is the statement to get the same:

log.info ​json."New England Schools__NE Schools\$".AggNumericData[0].ZIP​

UPDATE 2: Author of the problem mentioned, he is not not able get data together in his comment. So, adding here how to get both. Note that, I had to use minimum data to reproduce it since only part of the json was provided.

Getting both request data

enter image description here