title: how to read a JSON object from a URL with JsonReader?
body: <p>Without using additional JAR's or API's, strictly using <code>javax.json.*</code>, how can I read a JSON object from a URL?</p>
  
  <p>The <a href="http://docs.oracle.com/javaee/7/api/javax/json/JsonReader.html" rel="nofollow">javadocs</a> suggest that it's possible:</p>
  
  <pre><code> JsonReader jsonReader = Json.createReader(new StringReader("[]"));
   JsonArray array = jsonReader.readArray();
   jsonReader.close();
  </code></pre>
  
  <p>but aren't specific about how to use a <a href="https://docs.oracle.com/javase/7/docs/api/java/net/URI.html" rel="nofollow">URL or URI</a>.</p>
  
  <p>current code:</p>
  
  <pre><code>package net.bounceme.noagenda;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.StringReader;
  import javax.json.JsonObject;
  import static java.lang.System.out;
  import java.net.URL;
  import java.net.URLConnection;
  import java.nio.charset.Charset;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.json.Json;
  import javax.json.JsonArray;
  import javax.json.JsonReader;
  
  public class NoAgenda {
  
      public static void main(String[] args) {
          new NoAgenda().fromURL();
      }
  
      private void fromURL() {
          try {
              String jsonString = callURL("http://www.javascriptkit.com/dhtmltutors/javascriptkit.json");
          } catch (IOException ex) {
              Logger.getLogger(NoAgenda.class.getName()).log(Level.SEVERE, null, ex);
          }
          try (JsonReader jsonReader = Json.createReader(new StringReader("[]"))) {
              JsonArray array = jsonReader.readArray();
              out.println(array.toString());
          }
      }
  
      public String callURL(String myURL) throws IOException {
          System.out.println("Requested URL:" + myURL);
          StringBuilder sb = new StringBuilder();
          URLConnection urlConn = null;
          InputStreamReader in = null;
          URL url = new URL(myURL);
          urlConn = url.openConnection();
          if (urlConn != null) {
              urlConn.setReadTimeout(60 * 1000);
          }
          if (urlConn != null &amp;&amp; urlConn.getInputStream() != null) {
              in = new InputStreamReader(urlConn.getInputStream(),
                      Charset.defaultCharset());
              BufferedReader bufferedReader = new BufferedReader(in);
              if (bufferedReader != null) {
                  int cp;
                  while ((cp = bufferedReader.read()) != -1) {
                      sb.append((char) cp);
                  }
                  bufferedReader.close();
              }
          }
          in.close();
          return sb.toString();
      }
  
      public JsonObject buildBook() {
          JsonObject value = Json.createObjectBuilder()
                  .add("firstName", "John")
                  .add("lastName", "Smith")
                  .add("age", 25)
                  .add("address", Json.createObjectBuilder()
                          .add("streetAddress", "21 2nd Street")
                          .add("city", "New York")
                          .add("state", "NY")
                          .add("postalCode", "10021"))
                  .add("phoneNumber", Json.createArrayBuilder()
                          .add(Json.createObjectBuilder()
                                  .add("type", "home")
                                  .add("number", "212 555-1234"))
                          .add(Json.createObjectBuilder()
                                  .add("type", "fax")
                                  .add("number", "646 555-4567")))
                  .build();
          return value;
      }
  
  }
  </code></pre>
  
  <p>trying to get the JSON object for this page:</p>
  
  <p><a href="http://www.javascriptkit.com/dhtmltutors/javascriptkit.json" rel="nofollow">http://www.javascriptkit.com/dhtmltutors/javascriptkit.json</a></p>
  
  <p>again, to re-iterate, to emphasize, just using <code>javax</code> packages.  </p>