Prateek Naik
Prateek Naik

Reputation: 2792

How do i get the value using regex in jmeter

I need to correlate in jmeter for performance testing but am not able to fetch the required value.

    {
  "totalCount": 8,
  "data": [
    [
      "TEST_CLASS",
      "2020-05-18",
      "2020-05-18",
      9821844,
      "FY21 - WK 16",
      "FY21 - WK 16",
      null,
      "USER",
      "Name",
      "2020-05-11T10:45:14",
      283
    ],
    [
      "TEST_CLASS",
      "2020-05-18",
      "2020-05-18",
      9821842,
      "FY21 - WK 16",
      "FY21 - WK 16",
      null,
      "USER",
      "Name",
      "2020-05-11T10:30:45",
      283
    ],
    [
      "TEST_CLASS",
      "2020-05-18",
      "2020-05-18",
      9821848,
      "FY21 - WK 16",
      "FY21 - WK 16",
      null,
      "USER",
      "Name",
      "2020-05-11T11:11:21",
      283
    ],
    [
      "TEST_CLASS",
      "2020-05-18",
      "2020-05-18",
      9821843,
      "FY21 - WK 16",
      "FY21 - WK 16",
      null,
      "USER",
      "Name",
      "2020-05-11T10:39:03",
      283
    ],
    [
      "TEST_CLASS",
      "2020-05-18",
      "2020-05-18",
      9821846,
      "FY21 - WK 16",
      "FY21 - WK 16",
      null,
      "USER",
      "Name",
      "2020-05-11T10:54:55",
      283
    ],
    [
      "TEST_CLASS",
      "2020-05-18",
      "2020-05-18",
      9821849,
      "FY21 - WK 16",
      "FY21 - WK 16",
      null,
      "USER",
      "Name",
      "2020-05-11T12:35:45",
      283
    ],
    [
      "TEST_CLASS",
      "2020-05-18",
      "2020-05-18",
      9821845,
      "FY21 - WK 16",
      "FY21 - WK 16",
      null,
      "USER",
      "Name",
      "2020-05-11T10:50:57",
      283
    ],
    [
      "TEST_CLASS",
      "2020-05-18",
      "2020-05-18",
      9821847,
      "FY21 - WK 16",
      "FY21 - WK 16",
      null,
      "USER",
      "Name",
      "2020-05-11T11:05:58",
      283
    ]
  ],
  "additionalInfo": {
    "startDates": [
      "FY21 - WK 16"
    ],
    "createdByUsers": {
      "283": "USER Name"
    },
    "endDates": [
      "FY21 - WK 16"
    ]
  }
}

And every time i create record this json value will keep on increasing and need to fetch the last value 9821847 used regex but its not helping me All the info in json is correlated actually like "2020-05-18", "TEST_CLASS", "FY21 - WK 16", "USER", "Name" only thing which is not corelated is the UTC timestamp "2020-05-11T10:30:45", Even this one am generating using JSR223 post processor to use it in regex while creating record.

actual regex looks like : TEST_CLASS","${c3}","${c3}",(.*?),"${FY_WK}","${FY_WK}",null,"USER","Name","${utc_time}:

if i remove the correlated values then it looks like TEST_CLASS","2020-05-18","2020-05-18",(.*?),"FY21 - WK 16","FY21 - WK 16",null,"USER","Name","2020-05-11T11:05:

Upvotes: 1

Views: 56

Answers (1)

ararar
ararar

Reputation: 983

You can fetch all the values using JSON Extractor with below configurations

  • Variable names: MyVar
  • JSON Path expressions: $.data.[*].[3]
  • Match Numbers: -1
  • Default Values: NOT_FOUND

Then you can use ${__V(MyVar_${MyVar_matchNr})} to get the last value.

Upvotes: 2

Related Questions