title: Accessing jsonpath elements with nested objects
body: <p>I am looking to extract certain values from a JSON path of arrays and objects and use these values for further processing and am struggling with accessing those elements. Here is the JSON response:</p>
  
  <pre><code>[  
   {  
    "od_pair":"7015400:8727100",
    "buckets":[  
       {  
          "bucket":"C00",
          "original":2,
          "available":2
       },
       {  
          "bucket":"A01",
          "original":76,
          "available":0
       },
       {  
          "bucket":"B01",
          "original":672,
          "available":480
       }
      ]
      },
   {  
    "od_pair":"7015400:8814001",
    "buckets":[  
       {  
          "bucket":"C00",
          "original":2,
          "available":2
       },
       {  
          "bucket":"A01",
          "original":40,
          "available":40
       },
       {  
          "bucket":"B01",
          "original":672,
          "available":672
       },
       {  
          "bucket":"B03",
          "original":632,
          "available":632
       },
       {  
          "bucket":"B05",
          "original":558,
          "available":558
       }
      ]
   }
  ]
  </code></pre>
  
  <p>I tried accessing the root elements with $ but I could not get further with it.</p>
  
  <p>Here is the test method that I have written. I want to extract the value for od_pair and within each od_pair, I need to be able to retrieve the bucket codes and their available numbers.</p>
  
  <pre><code>public static void updateBuckets(String ServiceName, String DateOfJourney) throws Exception {
      File jsonExample = new File(System.getProperty("user.dir"), "\\LogAvResponse\\LogAvResponse.json");
      JsonPath jsonPath = new JsonPath(jsonExample);
  
      List&lt;Object&gt; LegList = jsonPath.getList("$");
      // List&lt;HashMap&lt;String, String&gt;&gt; jsonObjectsInArray = jsonPath.getList("$");
  
      int NoofLegs = LegList.size();
      System.out.println("No of legs :" + NoofLegs);
      for (int j = 0; j &lt;= NoofLegs; j++)
      // for (HashMap&lt;String, String&gt; jsonObject : jsonObjectsInArray) {
      {
  
          String OD_Pair = jsonPath.param("j", j).getString("[j].od_pair");
          // String OD_Pair = jsonObject.get("od_pair");
  
          System.out.println("OD Pair: " + OD_Pair);
          List&lt;Object&gt; BucketsList = jsonPath.param("j", j).getList("[j].buckets");
  
          int NoOfBuckets = BucketsList.size();
          // System.out.println("OD Pair: " + OD_Pair);
          System.out.println("no of Buckets: " + NoOfBuckets);
  
          for (int i = 0; i &lt; NoOfBuckets; i++) {
              String BucketCode = jsonPath.param("j", j).param("i", i).getString("[j].buckets[i].bucket");
              String Available = jsonPath.param("j", j).param("i", i).getString("[j].buckets[i].available");
  
              int BucketCodeColumn = XLUtils.getBucketCodeColumn(BucketCode);
              int ServiceRow = XLUtils.getServiceRow(ServiceName, DateOfJourney, OD_Pair);
              System.out.println("Row of " + ServiceName + ":" + DateOfJourney + "is:" + ServiceRow);
              System.out.println("Bucket Code column of " + BucketCode + " is: " + BucketCodeColumn);
              XLUtils.updateAvailability(ServiceRow, BucketCodeColumn, Available);
          }
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is the error I see:</p>
  
  <pre><code>Caused by: 
  org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
  failed:
  Script1.groovy: 1: unexpected token: [ @ line 1, column 27.
  restAssuredJsonRootObject.[j].od_pair
  </code></pre>
  
  <p>Can someone help me please?</p>