Search code examples
jsonwhile-loopjmeterautomated-testsjmespath

How to extract all id's from a JSON response using JSON JMESPasth Extractor in Jmeter?


I created a get request to get all the entries which is 997 entries and used JSON JMESPath Extractor to store the entries ids in a list. The JMESPath expression I used is entries[*].id and I used ForEach Controller to loop through the list and use each value of the list in next http request. The problem is that I want to get the ids of all 997 entries in the list, not just 10 values which is given at once by JMESPath extractor. I tried to take the length of entries as len and used While Controller to loop 100 times so that I can execute the next http request about 1000 times with condition ((${len}+3)/10). But, no matter how many times the loop executes, the values in the list obtained from JMESPath Extractor remains the same. The Json response I get is similar as shown below.

{
  "total": 997,
  "entries": [
    {
      "id": 123389,
      "parent-customer": [
        {
          "id": 123775,
          "value": "Donal Thornber"
        }
      ]
    }
}

I have only kept one entry for reference.


Solution

  • If you need to get all the IDs in a single shot - the easiest would be going for JSON Extractor, it provides .. deep scan operator so the expression like $..id will match all the id attributes values no matter where they are:

    enter image description here

    More information: API Testing With JMeter and the JSON Extractor