cancel
Showing results for 
Search instead for 
Did you mean: 

split json

Highlighted
New Contributor

split json

success_Response (java.lang.Object)

{"TTLRN":{"address":"tel:+9999999999","validity":"Valued","carrierid":"0000","carriername":"MYDORA","numbertype":"L","country":"Uganda","portingstatus":"false","mcc":"641","mnc":"11","deactivationdetail":{"carrierid":"","carriername":"","deactivationdate":""},"deactivationdate":"","requestid":"nistesting9","trackingid":"101580039301503395442144"}}

def success_Response = context.expand( '${TTLRN Request#Response#$}' )

def stringOutputSplitResponse=[]


stringOutputSplitResponse[] = success_Response.split(/"/)

def string = stringOutputSplitResponse[1]

log.info string

 

 

am unable to print TTLRN, expecting string to have assigned the value TTLRN

Tags (1)
7 REPLIES 7
Highlighted
Community Hero

Would you mind providing raw response? and what data you need to extract?



Regards,
Rao.
Highlighted
Community Hero

Maybe this will help.

 

package json
import com.eviware.soapui.support.XmlHolder
import groovy.json.*

// get the response of the JSON test step / request. 
// def response = context.expand( '${TestStepName s#Response}' ).toString()
// below is a string representing the value provided in the forum post. The above line can replace the below, with appropriate name of JSON response location

def success_Response = context.expand( '${TTLRN Request#Response#$}' )

def r = new JsonSlurper().parseText(success_Response)

log.info(r["TTLRN"])



---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
Highlighted
New Contributor

package json
import com.eviware.soapui.support.XmlHolder
import groovy.json.*

// get the response of the JSON test step / request.
// def response = context.expand( '${TestStepName s#Response}' ).toString()
// below is a string representing the value provided in the forum post.
//The above line can replace the below, with appropriate name of JSON response location

def response = context.expand( '${NOS 2.3 Request#Response}' ).toString()


def r = new JsonSlurper().parseText(response)
log.info(r["TTLRN"])


getting the following

 

response (java.lang.Object){"TTLRN":{"address":"tel:+9999999999","validity":"yes","carrierid":"ABCDE","carriername":"Best Mobile","numbertype":"M","country":"Angola","deactivationdetail":{"carrierid":"","carriername":"","deactivationdate":""},"deactivationdate":"","requestid":"test123","trackingid":"101"}}
r (java.lang.Object) 

 

There is no response for log.info(r["TTLRN"])

Highlighted
Community Hero

I don't think you want to use this:

 

def response = context.expand( '${NOS 2.3 Request#Response}' ).toString()

Try this?

 

def response = context.expand( '${NOS 2.3 Request#Response}' )



---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
Highlighted
Community Hero

I think the question is unclear. What data out of json do you want?


Regards,
Rao.
Highlighted
New Contributor

package json
import com.eviware.soapui.support.XmlHolder
import groovy.json.*

 

def response = context.expand( '${Request#Response#$}' )
def r = new JsonSlurper().parseText (response)

 

//I am trying to parse the following json response, I am expecting r to store the following

//{"TTLRN":{"address":"tel:+919886977381","validity":"true","carrierid":"ABCD","carriername":"Myphone","type":"M","country":"India","portingstatus":"false","mcc":"eee","mnc":"000","mdetail":{"carrierid":"","carriername":"","rdate":""},"ddate":"","requestid":"test123","trackingid":"8002"}}

 

log.info (r["TTLRN"])

 

//not able to understand what it should print.

 

 

 

 

 

Highlighted
Community Hero

Based on the code I gave you, r is storing:

//{"TTLRN":{"address":"tel:+919886977381","validity":"true","carrierid":"ABCD","carriername":"Myphone","type":"M","country":"India","portingstatus":"false","mcc":"eee","mnc":"000","mdetail":{"carrierid":"","carriername":"","rdate":""},"ddate":"","requestid":"test123","trackingid":"8002"}}

 

and

log.info (r["TTLRN"])

 

Will print out the contents of TTLRN:

{"address":"tel:+919886977381","validity":"true","carrierid":"ABCD","carriername":"Myphone","type":"M","country":"India","portingstatus":"false","mcc":"eee","mnc":"000","mdetail":{"carrierid":"","carriername":"","rdate":""},"ddate":"","requestid":"test123","trackingid":"8002"}

 

What do you want it to do? As @nmrao has stated, you are vague on your requirements so we can only guess at what you need help with. 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors