Skip to content

Instantly share code, notes, and snippets.

@rupzme
Created October 19, 2015 14:25
Show Gist options
  • Save rupzme/c579635791b6035eed72 to your computer and use it in GitHub Desktop.
Save rupzme/c579635791b6035eed72 to your computer and use it in GitHub Desktop.
SoapUI JSONPath Groovy Script Example Example
import static com.jayway.jsonpath.JsonPath.parse
def json = '''{"quote": {
"id": 12345,
"am ount": 100,
"links": [
{
"rel": "self",
"href": "http://localhost:8080/quote/777"
},
{
"rel": "customer",
"href": "http://localhost:8080/customer/12345"
}
]
}}
}'''
log.info parse(json).read('$.quote.id')
log.info parse(json).read('$.quote.am ount')
log.info parse(json).read('$.quote.links[0].href')
def quoteId = parse(json).read('$.quote.id')
log.info quoteId
assert quoteId==12345
assert parse(json).read('$.quote.id')==12345
@SouvikDcoder
Copy link

This has saved my bottom on a critical situation. Thank you for sharing this !!

@susnigdha1
Copy link

Hi, I am trying to use com.jayway.jsonpath (jsonpath-jar-2.2.0). I have copied the jar file under 'bin\ext' of Soapui....but it is failing to import classes from it. I also tried after placing it under 'lib' directory, but no luck so far. Could you let me know which version of jsonpath jar did you use and how you added it to Soapui?

@naXa777
Copy link

naXa777 commented Oct 5, 2017

@susnigdha1 com.jayway.jsonpath (jsonpath-jar-2.4.0) placed in 'bin/ext' directory of SoapUI works for me. You probably need to restart SoapUI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment