I am trying to get value of TxnType
from json request while mocking a response from SOAPUI. I want to respond with different responses based the value of TxnType
.
{
"Request": {
"UserId": "user",
"TxnType": "fetch"
}
}
Here is the groovy script to fetch the request value with fixed json
def json = """{
"Request": {
"UserId": "user",
"TxnType": "fetch"
}
}"""
def transactionType = new groovy.json.JsonSlurper().parseText(json).Request.TxnType
log.info "TxnType is : ${transactionType}"
You may quickly try the Demo
If you want to use the dynamic json in the mock script, then you can use below mock script dispatcher
def transactionType = new groovy.json.JsonSlurper().parseText(mockRequest.requestContent).Request.TxnType
log.info "TxnType is : ${transactionType}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With