Search code examples
jsonautomationjmeterperformance-testing

How to Use extracted JSON array data in loop in JMeter?


I have a workflow where user can create tickets using equipment numbers. Now from API response I'm getting equipment numbers. So using JSON extractor to store those in variable "equipmentNumber", with "match no. -1" (so getting all the equipment numbers which are present in response lets say 10 numbers) Now in next post request if is use variable "${equipmentNumber_1}" then first value from response gets passed. But I want to run this post request 10 times and use all equipmentNumber values in loop, which I am getting like equipmentNumber_1, equipmentNumber_2, equipmentNumber_3...till 10. So how to achieve that ?

[JSON Extractor](httpsenter image description here://i.sstatic.net/wZ858ZY8.png)


Solution

  • If you add a Debug Sampler or PostProcessor after the JSON Extractor you will see the following variables defined:

    equipmentNumber_1=foo
    equipmentNumber_2=bar
    equipmentNumber_3=baz
    equipmentNumber_matchNr=3
    

    In order to loop through them add a ForEach Controller and configure it like this:

    enter image description here

    Ądd your POST request as a child of the ForEach Controller and it will iterate as many times as there are matches in your JsonPath expression