title: Java - JSON - Return array of Objects within Object
body: <p>Hey fellow overflow users,
  I am having some issues wrapping my head fully around JSON calls in java.</p>
  
  <p>I am using the JSON LIB located here:</p>
  
  <p><a href="http://www.java2s.com/Code/JarDownload/java-json/java-json.jar.zip" rel="nofollow noreferrer">http://www.java2s.com/Code/JarDownload/java-json/java-json.jar.zip</a></p>
  
  <p>The JSON is currently structured as follows on the server end.</p>
  
  <pre><code>{  
     "patches":{  
        "patch1.zip":{  
           "name":"patch1.zip",
           "type":"file",
           "path":"patch1.zip",
           "size":15445899,
           "checksum":"ed4e2275ba67470d472c228a78df9897"
        },
        "patch2.zip":{  
           "name":"patch2.zip",
           "type":"file",
           "path":"patch2.zip",
           "size":1802040,
           "checksum":"59de97037e5398c5f0938ce49a3fa200"
        },
        "patch3.zip":{  
           "name":"patch3.zip",
           "type":"file",
           "path":"patch3.zip",
           "size":6382378,
           "checksum":"25efa1e9145a4777deaf589c5b28d9ad"
        },
        "user.cfg":{  
           "name":"user.cfg",
           "type":"file",
           "path":"user.cfg",
           "size":819,
           "checksum":"489a315ac832513f4581ed903ba2886e"
        }
     }
  }
  </code></pre>
  
  <p>And below is what I currently have.</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.HttpURLConnection;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  public class GetManifest {
  
      public static void main(String[] args) throws IOException, JSONException {
          try {
              String url = "SEE ABOVE"; //My URL requires a username and password. Please see JSON Above.
              URL obj = new URL(url);
              HttpURLConnection con = (HttpURLConnection) obj.openConnection();
              con.setRequestMethod("GET");
              con.setRequestProperty("User-Agent", "Mozilla/5.0");
  
              BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
              StringBuilder response = new StringBuilder();
              String line = "";
              while((line = in.readLine()) != null) {
                  response.append(line).append(System.getProperty("line.separator"));
              }
  
              JSONObject responseJSON = new JSONObject(response.toString());
              JSONObject loudScreaming = responseJSON.getJSONObject("patches");
  
              System.out.println(loudScreaming);
  
  
  
          } catch (MalformedURLException e) {
  
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>Please be easy with me, Java is not a language that I have really used before but I do have an okay understanding of its functions.</p>
  
  <p>The issue I am having is that when I print the variable loudScreaming (yes I am losing my mind) I get all of the JSON with the nested data.</p>
  
  <p>What I am actually trying to get is just the objects within patches to an array so I can then use the array to compare with a local copy and see if any of those file names are missing.  </p>
  
  <p>So in the end I am just trying to return the patches to an array without any of the nested data for now.</p>
  
  <p><strong>Answered by @AakashVerma in the comments. I have modified the code and you can see it working as below.</strong></p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.HttpURLConnection;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  public class GetManifest {
  
      public static void main(String[] args) throws IOException, JSONException {
          try {
              String url = "https://www.aerosimulations.com/wp-content/uploads/example.json";
              URL obj = new URL(url);
              HttpURLConnection con = (HttpURLConnection) obj.openConnection();
              con.setRequestMethod("GET");
              con.setRequestProperty("Content-Type", "application/json");
  
              BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
              StringBuilder response = new StringBuilder();
  
              String line = "";
              while((line = in.readLine()) != null) {
                  response.append(line).append(System.getProperty("line.separator"));
              }
  
              JSONObject responseJSON = new JSONObject(response.toString());
              JSONObject obj1_JSON = responseJSON.getJSONObject("patches");
  
              System.out.println(obj1_JSON);
  
              JSONArray patches = obj1_JSON.names();
  
              System.out.println(patches);
  
  
          } catch (MalformedURLException e) {
  
          }
  
      }
  
  }
  </code></pre>