Home > other >  How to extract nested elements in JSON response using JSON extractor
How to extract nested elements in JSON response using JSON extractor

Time:08-05

I need to extract an element based on a condition inside a nested JSON response.

{
   "cabin":"eco",
   "seatNumber":"15A",
   "travelers":[
      {
         "id":"7789",
         "seatCharacteristicsCodes":[
            "CH",
            "W"
         ],
         "seatAvailabilityStatus":"available",
         "prices":[
            {
               "base":40,
               "total":40,
               "currencyCode":"AED",
               "totalTaxes":0
            }
         ]
      }
   ],
   "coordinates":{
      "x":1,
      "y":0
   }
}

I need to check the "seatAvailabilityStatus" as "available" or not (which is inside "travelers"), if it is available, I need to get the "seatNumber" and proceed with the flow.

I have seen some example and tried like the below, but I am able to capture only the values which are associated to "travelers" like "id" or "prices":

$.travelers[?(@.seatAvailabilityStatus=="available")].id

But in my case, if the seatAvailabilityStatus is available I need to get the "seatNumber". Can anyone help?

enter image description here

More information: How to Use the JSON Extractor For Testing

  • Related