cantcode4mylife
cantcode4mylife

Reputation: 141

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

If I'd like to retrieve the JSON data from this github link: https://github.com/EthanRBrown/rrad/blob/master/addresses-us-100.json and store it into a JSONObject, is that possible? Is there another way for me to achieve this?

I'm using org.json.simple.JSONObject

Upvotes: 1

Views: 297

Answers (1)

kolorowa
kolorowa

Reputation: 36

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 */

Upvotes: 1

Related Questions