0

I'm using SoapUI Pro 4.5.0 and also a beginner for this tool. I need to get the value from the response (JSON format). Can anyone give me sample code for this?

Note: I'm using the REST based service not SOAP based service.

1
  • <dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <version>0.8.1</version> </dependency> Commented Jun 19, 2012 at 14:15

2 Answers 2

1

SoapUI includes JsonSlurper class in the groovy jar, so you just have to import it like

import groovy.json.JsonSlurper

and then the response is obtained as

responseContent = testRunner.testCase.getTestStepByName("<test_step_name>").getPropertyValue("Response")

jsonresponse = new JsonSlurper().parseTest(responseContent)

Now you can access the elements in response like

jsonresponse.id
Sign up to request clarification or add additional context in comments.

Comments

0

I would suggest using JSONPath from a Groovy script. You may need to add the JSONPath Jar to the /bin/ext directory.

I don't have SoapUI in front of me, but in the groovy script it would be something like:

def getResponse = context.expand( '${SomeGet#response}' )
def jsonSuff = JsonPath.read(getResponse, "\$..*")

Here is what was in my POM if you have trouble with the other JAR (I had created an external JAR that I used in SoapUI).

<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path</artifactId>
    <version>0.8.1</version>
</dependency>

And this was my import statement: import com.jayway.jsonpath.JsonPath

2 Comments

could you please tell me from where can I get the JSONPath.jar file?
I have downloaded the following jar files from here. grepcode.com/snapshot/repo1.maven.org/maven2/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.