0

Is there's a way I could extract the highest id: "15" of bld-appliance-1 using Json Path expression. Currently if use this Json expression "[?(@.name == 'bld-appliance-1')]..id" it returns me 3 result. I'm also aware I could use Match No but my catch here is the response is DYNAMIC I don't know if the 1st, 2nd or 3rd and etc is the highest id upon invocation. Your response is highly appreciated. Thank you so much.

Sample Response:

[{

    "id": "5",
    "name": "bld-appliance-1",
    "hostName": "bld-appliance-1"
},

{
    "id": "10",
    "name": "bld-appliance-1",
    "hostName": "bld-appliance-1"
},

{
    "id": "15",
    "name": "bld-appliance-1",
    "hostName": "bld-appliance-1"
},
{
    "id": "20",
    "name": "test-appliance-1",
    "hostName": "test-appliance-1"
}, {
    "id": "25",
    "name": "uat-appliance-1",
    "hostName": "uat-appliance-1"
}

]

Screenshot

1 Answer 1

0

You can do it using JSR223 PostProcessor and the following Groovy code:

def id = new groovy.json.JsonSlurper().parse(prev.getResponseData()).findAll {entry -> entry.name == 'bld-appliance-1'}.collect{entry -> entry.id as int}.max()

in case you need to store the result into a JMeter Variable you can add the next line:

vars.putObject('id', id)

More information:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.