Skip to content

Parsing_JSON_Extract_Object_Pass_To_Body_of_Another_Request_Body

Rajendra Prasad Reddy Penumalli edited this page Apr 17, 2020 · 1 revision
Parsing JSON Extract Object Pass To Body of Another Request Body
  • Send a request using HTTP Sample
  • Attach Post Processor
    • Use JSR-223 Processor Element
import groovy.json.*
def jsonResponse=prev.getResponseDataAsString()
def jsonSlurper = new JsonSlurper()
def obj = jsonSlurper.parseText(jsonResponse)
def totalRecords=obj.size();
log.info "----totalRecords: $totalRecords"
def index=0;
def objList=[]
obj.each{
    objList.add(obj)
}
def objListCount=objList.size()
//Generate a Random number between 0 to Maxcount Of obj list
def minListIndex=0
def maxListIndex=objectsCount-1
def randomObjListIndex = new Random().nextInt(maxListIndex+1)
def randomObject=numberList[randomListIndex]
vars.putObject("obj",objList[0]);
vars.put("objNumber",randomListIndex.toString());
### Use If Controller

If Controller Condition
${__javaScript(parseInt(vars.get("objCountToUpdate"))>1)}
${__groovy((vars.get("objCountToUpdate")).toInteger()>0)}

Clone this wiki locally