Search code examples
jmeterjmeter-plugins

Extract random ID from Json with multiple conditions


Can you please help me with a JMeter Json extractor to extract Random rid with below conditions rid !=0 and Name starts with "Test" For Example: for below json we should retrieve rid 3 or 7 as it is not 0 and Name starts with "Test"

{
    "Documents": [
        {
            "rId": 0,
            "Name": "Test_Sunil",
        }, 
        {
            "rid": 3,
            "Name": "Test_Sunil",
        }, 
        {
            "rid": 7,
            "Name": "Test_Kumar",
        }
        {
            "rid": "0",
            "Name": "Unknown",
        }
    ]
}

Solution

  • You can go for JSON Extractor and the following JSONPath expression:

    $..Documents[?(@.rId != 0 && @.Name=~ /Test.*/)].rid
    

    enter image description here

    Full configuration:

    enter image description here

    Refer extracted value as ${rid} later on where required.