简体   繁体   中英

JMeter JSON Extractor, extract all values of one key in a string

Using Apache JMeter ver 3.2 r1790745 (the latest) to test a JSON Web Service, the response is like:

[ {
   "id" : 3,
   "description" : "Back",
   "name" : "back"
}, {
   "id" : 1,
   "description" : "Front",
   "name" : "front"
}, {
   "id" : 6,
   "description" : "Left",
   "name" : "left"
}]

Want to parse the above response to get all ids in one string in JSON Extractor, like

3,1,6

My JSON Path expressions is like this:

$..id

But I got only the 1st id which is 3, the same result as $.[0].id Checking the result in a BeanShell PostProcessor. If I go to http://jsonpath.com/ $..id does give me

[
  3,
  1,
  6
]

If you configure your JSON Extractor like:

JSON Extractor Concatenation

You will get the required value as ${foo_ALL}

JMeter JSON连接


I don't think using Beanshell is the best way to check JMeter Variable value, going forward I would suggest using Debug Sampler instead, see How to Debug your Apache JMeter Script for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM