Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get values from json request in SOAPUI

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"
    }
}
like image 424
Pradhip Prakash Avatar asked Oct 17 '22 17:10

Pradhip Prakash


1 Answers

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}"
like image 87
Rao Avatar answered Dec 16 '22 17:12

Rao