title: How to fix com.google.gson.stream.MalformedJsonException
body: <p>I am trying to read a file from an external URL. The file contains data in JSON format. I am using the following code to read data from the file:</p>
  
  <pre><code>URL url = new URL(url);
  URLConnection request = url.openConnection();
  request.connect();JsonParser jp = new JsonParser();
  JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
  JsonObject rootobj = root.getAsJsonObject();
  JSONObject jsonObject = new JSONObject(rootobj.toString()); 
  </code></pre>
  
  <p>But I am getting the following exception while trying to run the code:</p>
  
  <pre><code>com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 2 column 2 
  </code></pre>
  
  <p>How can I fix this error? I have been spending some time now online to find s solution, but nothing helped me.</p>
  
  <p>I am adding the sample data below:</p>
  
  <pre><code>{"address":"P.O. Box 939","city":"Indian River","country":"US","dateAdded":"2018-02-08T04:35:45Z","dateUpdated":"2018-02-08T04:35:45Z","descriptions":[{"dateSeen":["2018-02-01T21:34:00.000Z"],"sourceURLs":["https://www.weddingwire.com/biz/rental-express-indian-river/2274f039e0c45443.html"],"value":"Contact Rental Express in Indian River on WeddingWire. Browse Event Rentals prices, photos and 1 reviews, with a rating of 5.0 out of 5"}],"features":[{"key":"Average Rating","value":["5.0"]},{"key":"Event Items","value":["Chairs","Dance Floor","Lights","Photobooth","Tables","Tent Accessories","Tents"]},{"key":"Food/Beverage Items","value":["China","Flatware","Glassware","Linens"]}],"keys":["us/mi/indianriver/p.o.box939/-1646083636"],"latitude":"45.4125117","longitude":"-84.6125364","name":"Rental Express","phones":["2312389696"],"postalCode":"49749","province":"MI","sourceURLs":["https://www.weddingwire.com/biz/rental-express-indian-river/2274f039e0c45443.html"],"id":"AWFztIreIxWefVJwy6hK"}
  {"address":"PO Box 6479","city":"Silver Spring","country":"US","dateAdded":"2018-02-08T04:35:35Z","dateUpdated":"2018-02-08T04:35:35Z","descriptions":[{"dateSeen":["2018-02-01T06:27:00.000Z"],"sourceURLs":["https://www.weddingwire.com/biz/indian-spring-country-club-silver-spring/9c020a063ea0fc84.html"],"value":"Contact Indian Spring Country Club in Silver Spring on WeddingWire. Browse Venue prices, photos and 3 reviews, with a rating of 4.3 out of 5"}],"features":[{"key":"Average Rating","value":["4.3"]}],"keys":["us/md/silverspring/pobox6479/1573156840"],"name":"Indian Spring Country Club","phones":["3018716000"],"postalCode":"20916","province":"MD","sourceURLs":["https://www.weddingwire.com/biz/indian-spring-country-club-silver-spring/9c020a063ea0fc84.html"],"id":"AWFztWW0IxWefVJwy7PH"}
  </code></pre>