Search code examples
regexjmeterhttprequesthttp-response-codes

Regex HTTP Response Body Message


I use a jmeter for REST testing. I have made a HTTP Request, and this is the response data:

{"id":11,"name":"value","password":null,"status":"ACTIVE","lastIp":"0.0.0.0","lastLogin":null,"addedDate":1429090984000}

I need just the ID (which is 11) in

{"id":11,....

I use the REGEX below :

([0-9].+?)

It works perfectly but it will be a problem if my ID more than 2 digits. I need to change the REGEX to :

([0-9][0-9].+?)

Is there any dynamic REGEX for my problem. Thank you for your attention.

Regards, Stefio


Solution

  • If you want any integer between {"id": and , use the following Regular Expression:

    {"id":(\d+),
    

    However the smarter way of dealing with JSON data could be JSON Path Extractor (available via JMeter Plugins), going forward this option can be much easier to use against complex JSON.

    See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") to learn more on syntax and use cases.