简体   繁体   中英

How to Extract specific value in list using JSON extractor in Jmeter

I have a question about Json extractor sampler in Jmeter. I have a json, that include list of components, the problem is that the order of the list is changing, and if I send the request in the morning the order of the list is not as in the evening . I want to extract the value "SalesPerson" with Id = 10606. The problem is that if the Id of 10606 is the first in response it is OK, But if it is in different order it brings wrong value. I need that in each time I send a request I can search Id 10606 and return the sales person (in the example "Bebeto"). Is it can be done? that it will extract exactly the specific value and not according it's place in response regards.

{
    "Error": null,
    "ErrorCode": 0,
    "Data": [{
        "Account": "Pro",
        "SalesPerson": "Ronaldo",
        "Id": 7722,
        "Name": "Brazil"
    }, {
        "Account": "Basic",
        "SalesPerson": "Bebeto",
        "Id": 10606,
        "Name": "USA"
    }, {
        "Account": "Basic",
        "SalesPerson": "Rivaldo",
        "Id": 13017,
        "Name": "Greece"
    }],
    "Totals": 3
}

Provided the sampler, that worked OK just if 10606 is the first in the list. I want it to extract Salesperson with Id 10606 regardless its position in the response. I want to provide 10606 and get the salesperson. In the provided scenario the results is wrong since its extract "Ronaldo" What am I missing?

在此处输入图片说明

Go for Filter Operator , something like:

$..[?(@.Id == '10606')].SalesPerson

should do the trick for you

Demo:

JMeter JSON路径提取器条件选择

More information and tricks: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

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