Search code examples
countjmeterrequestresponse

How to get total number of ids appearing in response in JMeter?


The json response body is:

{
  "status": 11111,
  "data": {
    "mylist": 
    {
      "1": [
        {
          "id": 1,
          "tId": 11
        }],
    
      "2": [
        {
          "id": 2,
          "tId": 12
        },
        {
          "id": 3,
          "tId": 12
  
        },
        {
          "id": 4,
          "tId": 13,
        }
      ]
}

Here, I want to get the count of ids present within "2" and not from "1". In above example I want to get idcount=3.


Solution

    1. Add JSON Extractor as a child of the request which returns the above response

    2. Configure it as follows:

      enter image description here

      Textual version of the JSON Path expression just in case: $.data.mylist.2.*.id

    3. You will get the following JMeter Variables (can be visualized using Debug Sampler):

      enter image description here

      id_1=2
      id_2=3
      id_3=4
      id_matchNr=3
      

      so you will be able to refer this 3 as ${id_matchNr} where required