0

I have the following JSON object r2,

[
   {
      "reserva_id":"200",
      "estancias":[
         {
            "reserva_estancia":"266",
            "huespedes":[
               {
                  "reserva_huesped":"272",
                  "reserva_estancia":"266",
                  "numero_huesped":"1",
                  "huesped":"123",
                  "huesped_nombre":"dos dos, dos",
                  "rfid":null
               },
               {
                  "reserva_huesped":"276",
                  "reserva_estancia":"266",
                  "numero_huesped":"2",
                  "huesped":"183",
                  "huesped_nombre":"MUESTRA MUESTRA, CARMEN",
                  "rfid":null
               }
            ]
         }
      ]
   },
   {
      "reserva_id":"201",
      "estancias":[
         {
            "huespedes":[
               {
                  "reserva_huesped":"273",
                  "reserva_estancia":"267",
                  "numero_huesped":"1",
                  "huesped":"148",
                  "huesped_nombre":"MUESTRA MUESTRA, CARMEN",
                  "rfid":null
               },
               {
                  "reserva_huesped":"277",
                  "reserva_estancia":"267",
                  "numero_huesped":"2",
                  "huesped":"187",
                  "huesped_nombre":"TEST TEST, TESTCIVITFUN",
                  "rfid":null
               }
            ]
         }
      ]
   }
]

I am trying to get the first huesped for each reservation, and for that I am using the following script, to create a list called profiles and store profileId's:

def profiles = jsonpath(r2,'$..[:].estancias[:].huespedes[0].huesped')

The output should be the following:

[
  "123",
  "148"
]

However, when I print profiles.text I get all the content of the estancias object, instead of just the huesped number.

DMi
  • 31
  • 4
  • Where do you use this? JMeter, SoapUI? I cannot add further instructions since I do not know your environment. – wp78de Nov 25 '20 at 05:40

1 Answers1

0

When using Jayway's JSONPath like this I get the desired oputput:

$..[*].estancias[*].huespedes[0].huesped

You can try the path expression with your JSON here online.

wp78de
  • 18,207
  • 7
  • 43
  • 71