Search code examples
groovyjmeterjmeter-pluginsjmeter-4.0

extract specific value from json response using regular expression - latest


My last question was closed somehow. hence creating a new question.

I've the below JSON response received from the HTTP request. I want to extract the page number(i.e 1574) from the node. can some one please assist how to do it with Regular expression in jmeter ? or any other approach?

updated response:

 "links": {
        "first": {
            "href": "https://example.com/aaa/a/aa?page%5Bnumber%5D=1&page%5Bsize%5D=25&sort=-modifiedDate&page[number]=1",
            "rel": "first"
        },
        "next": {
            "href": "https://example.com/aaa/a/aa?page%5Bnumber%5D=1&page%5Bsize%5D=25&sort=-modifiedDate&page[number]=2",
            "rel": "next"
        },
        "last": {
            "href": "https://example.com/aaa/a/aa?page%5Bnumber%5D=1&page%5Bsize%5D=25&sort=-modifiedDate&page[number]=1574",
            "rel": "last"
        }
    },
    "meta": {
        "totalCount": 39334
    }
}

I have tried below data in Regular expression in Jmeter but could not retrieve 1574 value.

Regular expression: links.last.href.=(\d+)" Template: $1$ Match: 1 Default value: pageno_not_found


Solution

  • The easiest solution is going for 2 Post Processors:

    1. JSON JMESPath Extractor to get the href attribute for the "last" link:

      enter image description here

    2. Regular Expression Extractor to get the "number" from the variable generated by the JSON JMESPath Extractor

      enter image description here

    Demo:

    enter image description here