0
votes

I have used json path extractor to find multiple matches from a json response. and got output:

IDType_Extract_1={"contentType":"LIVE","id":103}
IDType_Extract_2={"contentType":"CATCH_UP","id":6441631}
IDType_Extract_3={"contentType":"MOVIES","id":129}

Now, i want to split these two values and pass any random (contentType,id) pair in next jmeter http request.

Which postprocessor should i use and how to extract values.

I was using beanshell assertion and beanshell postprocessor but not able to extract it.

string[] value = vars.get{"IDType_Extract_1"};

  string[] type = value.split{","};

In debug sampler, no value is coming in variables.

2

2 Answers

0
votes
  1. Your syntax is not correct, it should be

    string[] value = vars.get("IDType_Extract_1");

  2. Your approach is not correct, since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting and Groovy provides JsonSlurper class which is handy for parsing JSON.

Assuming all above

  • Add JSR223 PreProcessor as a child of the request you want to parameterize
  • Put the following code into "Script" area:

    def randomNumber = org.apache.commons.lang3.RandomUtils.nextInt(1, (vars.get('IDType_Extract_matchNr') as int) + 1)
    def entry = new groovy.json.JsonSlurper().parseText(vars.get('IDType_Extract_' + randomNumber))
    vars.put('contentType', entry.contentType)
    vars.put('id', entry.id as String)
    
  • That's it, refer the random extracted values as ${contentType} and ${id} where required:

Demo:

enter image description here

More information:

0
votes

You should use JSON Extractor, either get specific values in original JSON Extractor adding to expression suffix .contentType

Another option ti create a new JSON Extractor using exists JMeter variable and $.contentType as expression :

JSON PostProcessor enables you extract data from JSON responses using JSON-PATH syntax. This post processor is very similar to Regular expression extractor. It must be placed as a child of HTTP Sampler or any other sampler that has responses.