Jmeter extracting fields/parsing JSON response

2019-01-04 03:37发布

I have following JSON format in response body

[
    {
        "Name" : "Prashant",
        "City" : "Sydney"
    },
    {
        "Name" : "Yogi",
        "City" : "London"
    }
]

What is the better way for checking if this array has any records and if yes give me "Name" for first array index. I am using jp@gc JSON extractor plugin for jMeter.

Is it possible to parse this using a plugin or do I need to do it using regular expressions?

5条回答
唯我独甜
2楼-- · 2019-01-04 04:08

We can add a regular expression extractor for fetching the value from the response.

Like This:

Regular expression extractor

查看更多
太酷不给撩
3楼-- · 2019-01-04 04:11

Working with JSON in JMeter is not quite easy as JMeter was designed long ago before JSON was invented. There are some extensions however that make life easier:

http://www.ubik-ingenierie.com/blog/extract-json-content-efficiently-with-jmeter-using-json-path-syntax-with-ubik-load-pack/

查看更多
再贱就再见
4楼-- · 2019-01-04 04:18

If possible, always use Regular Expression Extractor. Try to avoid JSON / XPATH / Other extractors. They might look easy to use. But they consume more memory and time. It will affect the performance of your test plan.

source: http://www.testautomationguru.com/jmeter-response-data-extractors-comparison/

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-01-04 04:23

I am not sure about your plugin but if it supports JSON path expressions it should be possible.
Try with this expression: $.[0].Name.

This is the plugin I use: http://jmeter-plugins.org/wiki/JSONPathExtractor/ and given expression works with it.

You can find more about JSON Path expressions here: http://goessner.net/articles/JsonPath/index.html#e2.

查看更多
爷的心禁止访问
6楼-- · 2019-01-04 04:25

Using Ubik Load Pack JSON plugin for JMeter which is part of JMeter since version 3.0 (donated plugin) and called JSON Extractor, you can do it:

Test Plan overview:

enter image description here

ULP_JSON PostProcessor:

enter image description here

If Controller:

enter image description here

And here is the run result:

enter image description here

So as you can see it is possible with our solution

查看更多
登录 后发表回答