0
votes

I am using JMeter to test a web application. The application returns JSON that looks like the following:

{"type":"8","id":"2093638401"}
{"type":"9","id":"20843301"}
{"type":"14","id":"20564501"}

I need to get a count based on type.

I have tried adding foreach controller with a regular expression extractor, but Im not sure I have done it correctly:

  • Apply to: Main sample only
  • Response field to check: Body
  • Reference name: match_type
  • Regular Expression: "type":"(\d)"
  • Template: $1$
  • Match no.: -1

Im new to JMeter so Im not sure if Im doing any of this correctly.

Thanks

1
can you clarify what you mean by "I need to get a count based on type." ?UBIK LOAD PACK
That's not really JSON. Is it actually a JSON array (e.g., [{"type":"8","id":"23324"},{"type":"42","id":"22224"}])?fncomp

1 Answers

0
votes

If you want to operate on both type and id in single sampler, I think simple regex and ForEach controller won't be sufficient. You will have to write two regex extractor followed by while controller with BSF processor (javascript or beanshell) to extract both the values and export them to jmeter variable. Something of following type

- First Request
  - Regex extractor for type
  - Regex extractor for id
  - BSF processor (to initialize the loopcount=0 and the total_matches of matches that you found)
- while controller (loopcount < total_matches)
  - BSF processor 
     - export/set current_type = type_$loopcount
     - export/set current_id = id_$loopcount
     - increment loopcount
  - USE current_type and current_id in whatever sampler you like

== Update ==

This http://goo.gl/w3u1r tutorial depicts exactly how to go about it.