Json Extractor in JMeter

124 Views Asked by At

I am using JSON extractor in JMeter. Below is my Response Body. I am using the Json path expression to capture the value, which is working fine.

JSON_PathExpression

Apart from the above condition, I need to add one more condition.

If the "travelID" length is equal to 33, then only I need to get the BoundID.

Example : AAA-AB1234-AAABBB-2022-11-10-1111

Total length or count of the above travelID is 33, but sometime I used to get 31,32 also but I need to capture the Bound ID only when the length is 33. Is that feasible ? Please help on the same PFB sample response body.

{
    "data": {
        "RenewalDetails": [
            {
                "ExpiryDetails": {
                    "duration": "xxxxx",
                    "destination": "XXX",
                    "from": "XXX",
                    "value": 2,
                    "segments": [
                        {
                            "valudeid": "xxx-xx6262-xxxyyy-1111-11-11-1111"
                        }
                    ]
                },
                "Itemdetails": [
                    {
                        "BoundId": "xxx-1-xxx1-111111111111-1",
                        "isexpired": true,
                        "FamilyCode": "PREMIUM",
                        "availabilityDetails": [
                            {
                                "travelID": "AAA-AB1234-AAABBB-2022-11-10-1111",
                                "quota": "X",
                                "scale": "XXX",
                                "class": "X"
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "warnings": [
        {
            "code": "xxxx",
            "detail": "xxxxxxxx",
            "title": "xxxxxxxx"
        }
    ]
}

1

There are 1 best solutions below

1
Dmitri T On

I don't think it's possible with JSON Extractor, I would rather suggest going for JSR223 PostProcessor and the following Groovy code:

def BoundId = new groovy.json.JsonSlurper().parse(prev.getResponseData())
        .data.RenewalDetails[0].Itemdetails.find { itemDetail ->
    itemDetail.availabilityDetails[0].travelID.length() == 33
}?.BoundId


vars.put('BoundId', BoundId ?: 'Not Found')

You will be able to refer extracted value as ${BoundId} later on where required.