How to get a JSONObject from a public github repository in Java?

Viewed 26
1 Answers

Yes it is possible.

You might want to access raw link instead of browser friendly one - https://raw.githubusercontent.com/EthanRBrown/rrad/master/addresses-us-100.json

Then you download that for example with HttpClient and then convert String into JSONObject.

CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet request = new HttpGet(address);
CloseableHttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity);

/* now convert String result to JSONObject */
Related