title: How to parse JSON file?
body: <p>Simple situation - </p>
  
  <ol>
  <li>read a json file</li>
  <li>discover all key-value pairs</li>
  <li>compare key-value pairs</li>
  </ol>
  
  <p>I tried gson, package from json.org, but can't seem to get far with it.</p>
  
  <p>Can someone please provide a clear sample in Java on how to take a file, read it, end up with json objec I can get key/value pairs from.</p>
  
  <p>Consider this:</p>
  
  <pre><code>private void runThroughJson(JsonObject jsonObject) {
      for (final Entry&lt;String, JsonElement&gt; entry : jsonObject.entrySet()) {
  
          final String key = entry.getKey();
          final JsonElement value = entry.getValue();
  
          System.out.println(key + " - " + value);
  
          if (value.isJsonObject()) {
              runThroughJson(value.getAsJsonObject());
          } else {                
              int ix = value.getAsString().indexOf('[');
              int ig = value.getAsString().lastIndexOf(']');
  
              System.out.println(ix);
              System.out.println(ig);
  
              String a = value.getAsString().substring(ix, ig);
              JsonElement jsonElement = parser.parse(a);
              runThroughJson(jsonElement.getAsJsonObject());
          }
      }
  }
  </code></pre>
  
  <p>Logically, it seems alright, however, i get an exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalStateException
      at com.google.gson.JsonArray.getAsString(JsonArray.java:133)
      at com.cme.esg.bk.TryGson.runThroughJson(TryGson.java:46)
      at com.cme.esg.bk.TryGson.runThroughJson(TryGson.java:44)
      at com.cme.esg.bk.TryGson.goForIt(TryGson.java:32)
      at com.cme.esg.bk.TryGson.main(TryGson.java:16)
  </code></pre>
  
  <p>Can you please advise that am i missing.</p>