How to randomly select data from a sample JSON File for a request body in JMeter?

52 Views Asked by At

I have to select a sample object from a JSON File for randomizing the request body for each request in JMeter

I want to randomize the request body in JMeter from a JSON File. It should be done in the Pre Processor as far as i know but there might be other ways to do it. THe JSON File contains many claim such as { "claim":{ data1:point1, data2:point2 }, "claim":{ data1:point1, data2:point2 } }

So the request body must a randomly selected claim object.

1

There are 1 best solutions below

0
Dmitri T On

You need to provide a valid JSON file in order to get comprehensive help.

If for some reasons you are not willing to use JSR223 PreProcessor with Groovy for parsing the file and building the proper request body you can do something like:

  1. Use HTTP Request sampler with file protocol to read the JSON file from the file system like it's described in How to Extract Data From Files With JMeter article
  2. Use either JSON Extractor or JSON JMESPath Extractor to extract "random claim" from the file and save it into a JMeter Variable
  3. Use the variable from step 2 where required.