title: How to extract a specific key-value pair for a complex-nested json structure using Gson API
body: <p>My final aim is to have a map with the a authored name and the extracted value from the Json below (english-value for param1 and param2). e.g: {(S-W: 5000 w),(R-W: 5800 W)}    </p>
  
  <pre><code>string =  
  
  [
      {
          "title":"Specifications",
          "sort":1,
          "specValues":[
              {
              "name":"xxx",
              "type":"yyy",
              "englishValue":"xx.0 lb",
              "metricValue":"yy.0 kg",
              "sort":4
              },
              {
              "name":"Param1",
              "type":"measurement",
              "englishValue":"5000.0 W",
              "metricValue":"5000.0 W",
              "sort":99
              },
              {
              "name":"Param2",
              "type":"measurement",
              "englishValue":"5800.0 W",
              "metricValue":"5800.0 W",
              "sort":99
              },
              {
              "name":"Frequency",
              "type":"measurement",
              "englishValue":"60.0 Hz",
              "metricValue":"60.0 Hz",
              "sort":99
              }
          ]
      }
  ]
  </code></pre>
  
  <p>Here is my code to extract it and the errors below it:</p>
  
  <pre><code>public Map&lt;String, String&gt; parseGenGson(String jsonLine) {
       Map &lt;String,String&gt; generatorMap = new LinkedHashMap &lt;String,String&gt;();
       try {
          JsonElement jelement = new JsonParser().parse(jsonLine);
  
          JsonArray  jarray1 = jelement.getAsJsonArray();
          JsonArray jarray = (JsonArray) jarray1.get(2);
          JsonObject jobject1 = jarray.getAsJsonObject();
          JsonArray jarray2 = jobject1.getAsJsonArray("specValue");
          JsonObject jobject = jarray2.get(1).getAsJsonObject();
          String result1 = jobject.get("englishValue").toString();
          generatorMap.put("Running Watts",result1);
          jobject = jarray.get(2).getAsJsonObject();
          String result2 = jobject.get("englishValue").toString();
          generatorMap.put("Starting Watts",result2);         
          log.info("Map of generators" + generatorMap);
          return generatorMap;
       } catch (Exception e){
           log.error(e.getMessage());
           return generatorMap;
       }
      }
  </code></pre>
  
  <p>Error: </p>
  
  <pre><code>Index: 2, Size: 1
  </code></pre>
  
  <p>Something is off with the structure I am using, I used GSon API. Any ideas?</p>