title: Unexpected token END OF FILE at position 0 while parsing JSON
body: <p>In order to find out weather the JSON element is JSONArray or JSONObject type, I am getting <em>Unexpected token END OF FILE at position 0</em> error.</p>
  
  <p>My JSON is:</p>
  
  <pre><code>{"colors":[{"color":"red","value":"#00"},{"color":"white","value":"#000g"}]}
  </code></pre>
  
  <p>My code is: </p>
  
  <pre><code>java.io.FileReader reader = new java.io.FileReader("jsonpath");
  org.json.simple.parser.JSONParser parser = new JSONParser();
  System.Out.Println("aaaaaa JSON Class: "+parser.parse(reader).getClass());
  if(parser.parse(reader) instanceof org.json.simple.JSONArray)
      System.Out.Println("JSONArray");
  else if(parser.parse(reader) instanceof org.json.simple.JSONObject)
      System.Out.Println("JSONObject");
  </code></pre>
  
  <p>When I run above code it shows this output</p>
  
  <pre><code>aaaaaa JSON Class: class org.json.simple.JSONObject Unexpected token END OF FILE at popsition 0
  at org.json.simple.parser.JSONParser(Unknown Source)
  .
  .
  .
  &lt;rest of the exception&gt;
  </code></pre>
  
  <p>I don't understand why this exception is occurring.
  Please help me out.</p>
  
  <p><strong>Some more details after edit:</strong></p>
  
  <p>My this code is working fine with the given json file:</p>
  
  <pre><code>java.io.FileReader reader = new java.io.FileReader("jsonpath");
  org.json.simple.parser.JSONParser parser = new JSONParser();
  org.json.simple.JSONObject object = (JSONObject)parser.parse(reader);
  System.Out.Println("JSONObject: "+object);
  org.json.simple.JSONArray array = (JSONArray)object.get("colors");
  System.Out.Println("JSONArray: "+array);
  </code></pre>
  
  <p>Output of above code:</p>
  
  <pre><code>JSONObject: {"colors":[{"color":"red","value":"#00"},{"color":"white","value":"#000g"}]}
  JSONArray: [{"color":"red","value":"#00"},{"color":"white","value":"#000g"}]
  </code></pre>
  
  <p>But I want to dynamically parse the JSON without knowing the JSON structure.
  I want to do something like this:</p>
  
  <pre><code>  if(json is object)
      JSONObject object = (JSONObject)parser.parse(reader);
    else if (json is array)
      JSONArray array = (JSONArray)parser.parse(reader);
  </code></pre>
  
  <p>Thanks.</p>