title: Java Gson - Get specific values from JSON tree
body: <p>I have this JSON:</p>
  
  <pre><code>request_time: "2018-03-13T00:59:44+00:00",
  stops: [
  {
  atcocode: "370023715",
  mode: "bus",
  name: "AG1",
  stop_name: "AG1",
  smscode: "37023715",
  bearing: "N",
  locality: "Sheffield Centre",
  indicator: "AG1",
  longitude: -1.46616,
  latitude: 53.38248,
  distance: 57
  },
  {
  atcocode: "370027281",
  mode: "bus",
  name: "AG12",
  stop_name: "AG12",
  smscode: "37027281",
  bearing: "N",
  locality: "Sheffield Centre",
  indicator: "AG12",
  longitude: -1.46583,
  latitude: 53.38228,
  distance: 77
  }
  ]
  }
  </code></pre>
  
  <p>I would like to retrieve and store each locality and atocode within this sub tree, in an array. I currently have this java code, but it only displays everything within the sub tree :</p>
  
  <pre><code>JsonParser parser = new JsonParser();
      JsonElement element = parser.parse(json);
  
      response.setContentType("text/html");
              PrintWriter  out  = response.getWriter();
              out.println("&lt;html&gt;&lt;body&gt;");
  
      if (element.isJsonObject()){
          JsonObject bus = element.getAsJsonObject();
  
          JsonArray array = bus.getAsJsonArray("stops");
          for (int i = 0; i &lt; array.size(); i++){
              out.println(array.get(i)); 
  
  }
  </code></pre>