I’ve read a few tutorials on jMeter RegEx extraction but it’s not working. I’m using jMeter 2.7.
I have this JSON:
{"address":{"id":26,"user_id":1,"genre":"billing","first_name":"testFN1","last_name":"testLN1","company":null,"street1":null,"street2":null,"city":null,"state":"DC","zip":null,"country":null,"country_iso2":null,"phone1":"32432424322","phone2":null}}
and this RegEx Extractor: “id”:(.+?), here’s the screenshot of jMeter

For the extraction, I get $new_address_id = 2, instead of 26. Any ideas?
UPDATE 6/26/2012:
Thanks Cylian for your suggestion. It is very helpful. I ended up changing it to: "id":(\d+).
I also did a find a replace in the JMX file for
<stringProp name="RegexExtractor.regex">"id":(.+?,)</stringProp>
and replace with
<stringProp name="RegexExtractor.regex">"id":(\d+)</stringProp>
Which made the fix quickly. Thanks!
I suggest you take a look at :
http://jmeter-plugins.org/wiki/JSONPathExtractor/
This section (JSON utils (JSON Path Assertion, JSON Path Extractor, JSON Formatter)) in particular for this case. These are set of jmeter tools developed in my company, they’re very useful.
Let’s take your case as example. The test case looks like this :
So dummy sample returns response, just like the one you specified :
JSON extraction is very simple :
And there you go no need for fancy regexes. Result is 26 (that is what I see in debug sampler).
Update from question in comments :
If you were to have list of values i.e. :
List with 2 address-es , 1 has id 26 and another one 6. The Json Path
$.address.idshould return both of these ids. I just saw sampler source code and it’s not possible to get the count however you can do it by adding another post processor to your sample i.eBSF Samplerand by adding this code :Where
${add}is any variable where you stored results of$.address.id.