Search code examples
javarest-assured-jsonpath

RestAssured how to get the name of a value from response


I did some research in satckoverflow. I could not find any answer. From the response below how can I find out what the value is after payment? It can either be bankAccount or creditCard. Depending on the value I get, I will run the next script. In the example below you can see that the current value is bankAccount.

{
"code": "I00001",
"description": "Successful.",
"customerProfileId": "1234",
"paymentProfles": [{
    "customerPaymentProfileId": "9874",
    "billingAddress": {
        "address": "123 Steven Road",
        "city": "Hopkins",
        "state": "MN",
        "zipcode": "55344",
        "phoneNumber": "507-3821122",
        "country": "USA"
    },
    "payment": {
        "bankAccount": {
            "accountNumber": "XXXX1234",
            "accountType": "CHECKING",
            "eCheckType": "WEB",
            "nameOnAccount": "QA Tes1t"
        }
    }
}]

}

Thanks in advance for your time and help.


Solution

  • "payment" will be parent key under which either "bankAccount" or "creditCard" would be present. You can just deserialize "payment" into Map and then get the key of it. Now based on key name you can write ur next step.