2
votes

I have to parse the json response and get the value of a field "bookName": "MyBook 001"

Here is my response:

{  
   "meta":{  
      "/data/library":{  
         "bookName":"MyBook 001",
         "/book/ID":{  
            "readOnly":true,
            "optional":false,
            "hidden":true
         }
      }
   }
}

This is my script assertion:

import groovy.json.JsonSlurper
def ResponseMessage = messageExchange.response.responseContent
def jsonResponse = new JsonSlurper().parseText(ResponseMessage)
def bName =jsonResponse.meta.data/library.bookName
log.info bName

I get error as no such property library I tried using Soapui 'get data' option. But context.expand is not working when running from maven/jenkins.

How do I parse this response containing data/library?

1
Any specific reason for having / in the property name? - Rao

1 Answers

1
votes

Just a trivial change needed to your script. Since there is special character, put the property name inside of quotes.

Change from: def bName =jsonResponse.meta.data/library.bookName

To : def bName =jsonResponse.meta.'data/library'.bookName

You can also find the value of bookName retrieved as shown below.

enter image description here