0
{
    "response":
    {
        "responseData":
         {
             "createdDate":"2016-04-23 14:39:35",
             "modifiedDate":"2016-04-23 14:39:35",
             "catalogID":1009
         }
    }
}

Here is sample JSON data for reference. I need to extract the value of catalogID=1009. How to extract the value of catalogID?? can anyone please share your idea???

What is the regular expression to retrieve the catalogID??

1
  • jmeter allows jsonpath..use that only..its much better option than regex Commented Apr 23, 2016 at 9:33

3 Answers 3

2

Use the following regular expression extractor configuration:

  • Reference Name: variable name of your choice, i.e. catalogID
  • Regular Expression: "catalogID":(\d+)
  • Template: $1$

Refer extracted value as ${catalogID} where required.

Few tips:

  1. You can use View Results Tree listener in RegExp Tester mode to test your regular expressions against real response:

    Regexp Tester

    See How to debug your Apache JMeter script article for more details.

  2. There is JSON Path Extractor available via JMeter Plugins which allows using JSON Path language (more handy than regular expressions when it comes to JSON), for example the relevant query to get "catalogID" will be as simple as:

    $..catalogID[0]
    

    There is also an online JSON Path Expression Tester

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for ur effort but not working for this Regular Expression: "catalogID":(\d+) . I need to extract inside the array data. can u pls tell me the purpose of template ? and please add the screenshot for regular expression extractor page. I want know how ur gave the reg exp.
0

If you want to use regex, use

"catalogID":(.+?)

or

"catalogID":(\d+) <-- For only digits

You can also install the plugin JSONPath for jmeter and use this instead

$.response[0].responseData[0].catalogID

More info

5 Comments

I had used this "catalogID":"(.+?)" reg exp but it was not retrieve the value(1009). Json path extractor is not recommended in my organization.
@tsivarajan why are using quotes??There are no quotes in input after :
i had tried both ways with quotes and without quotes. but its not working. Verify this link (eclipsesource.com/blogs/2014/06/12/…) in here they r using quotes.
@tsivarajan i think they are using quotes because there is quotes in input they have shown..try to capture any other thing and see if it works
but i need to extract string as well as integer. can u pls share if u find any solution?
0

I have found the solution for this question.

Here you want to extract the integer value means then use this requalar expression like "catalogID":(.*?),

String means "catalogID":"(.*?)",

Lets do it!

3 Comments

This is exactly what I had written in my answer and told you to do in comments and why ,?
but u didn't mentioned , (comma). It will show error message without give the ,(comma). I don't no why its required.
its weird because the other answer also does not have ,

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.