使用Jmeter中的“Json Path Extractor”从JSON响应中提取多个值

时间:2021-07-26 19:40:51
{
    "response_time": 0.014376163482666016,
    "applications": [
        {
            "api_key": "blted0e7982e1cf62a8",
            "name": "gta",
            "uid": "gta",
            "account_name": "jack"
        },
        {
            "api_key": "blt1423c40d23e4a423",
            "name": "cellapp",
            "uid": "cellapp",
            "account_name": "max"
        }
    ]
}

Please help me to extract the account_name = max using Jmeter Json Path Extractor.

请帮我使用Jmeter Json Path Extractor提取account_name = max。

3 个解决方案

#1


5  

$.applications.name[2] must return exactly the second name element.

$ .applications.name [2]必须完全返回第二个名称元素。

If you use JSONPath like $..name this will look for all elements named name and the plugin will return a single string value which will look like ["gta","cellapp"]. You can parse this string if necessary.

如果您使用类似$ .. name的JSONPath,那么将查找名为name的所有元素,插件将返回单个字符串值,该值看起来像[“gta”,“cellapp”]。如有必要,您可以解析此字符串。

Check the this site on how to build JSONPath expressions: http://goessner.net/articles/JsonPath/index.html#e2.

检查此站点有关如何构建JSONPath表达式的信息:http://goessner.net/articles/JsonPath/index.html#e2。

#2


1  

With the expresion ->

随着表达 - >

$.[?(@.account_name=='max')].account_name

You will get

你会得到

[
  "max"
]

With the expresion ->

随着表达 - >

$.[?(@.account_name=='max')]

You will get

你会得到

[
    {
        "api_key": "blt1423c40d23e4a423",
        "name": "cellapp",
        "uid": "cellapp",
        "account_name": "max"
    }
]

With the expresion ->

随着表达 - >

$.[?(/max/.test(@.account_name))]

You will get a "like" condition

你会得到一个“喜欢”的条件

[
    {
        "api_key": "blt1423c40d23e4a423",
        "name": "cellapp",
        "uid": "cellapp",
        "account_name": "max"
    }
]

#3


-1  

$..[?(@.account_name =='max')].account_name

#1


5  

$.applications.name[2] must return exactly the second name element.

$ .applications.name [2]必须完全返回第二个名称元素。

If you use JSONPath like $..name this will look for all elements named name and the plugin will return a single string value which will look like ["gta","cellapp"]. You can parse this string if necessary.

如果您使用类似$ .. name的JSONPath,那么将查找名为name的所有元素,插件将返回单个字符串值,该值看起来像[“gta”,“cellapp”]。如有必要,您可以解析此字符串。

Check the this site on how to build JSONPath expressions: http://goessner.net/articles/JsonPath/index.html#e2.

检查此站点有关如何构建JSONPath表达式的信息:http://goessner.net/articles/JsonPath/index.html#e2。

#2


1  

With the expresion ->

随着表达 - >

$.[?(@.account_name=='max')].account_name

You will get

你会得到

[
  "max"
]

With the expresion ->

随着表达 - >

$.[?(@.account_name=='max')]

You will get

你会得到

[
    {
        "api_key": "blt1423c40d23e4a423",
        "name": "cellapp",
        "uid": "cellapp",
        "account_name": "max"
    }
]

With the expresion ->

随着表达 - >

$.[?(/max/.test(@.account_name))]

You will get a "like" condition

你会得到一个“喜欢”的条件

[
    {
        "api_key": "blt1423c40d23e4a423",
        "name": "cellapp",
        "uid": "cellapp",
        "account_name": "max"
    }
]

#3


-1  

$..[?(@.account_name =='max')].account_name