jmeterperformance-testingjmeter-pluginsbeanshelljsr223

Remove json key from response in jmeter and feed processed response as request to next sampler


I have a sampler 1 which generates response like

{ ....... updatedAt: dateAndtime, createdAt: datetime}

Now this response i have to process by removing updatedAt , createdAt key, values and then feed same as request body to next sampler. Could any one help , how to do this?


Solution

    1. Add JSR223 PostProcessor as a child of the request which returns the above JSON

    2. Put the following code into "Script" area:

      def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
      
      response.remove('updatedAt')
      response.remove('createdAt')
      
      vars.put('request', new groovy.json.JsonBuilder(response).toPrettyString())
      
    3. Refer the amended request value as ${request} later on where required

    More information: