import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.ArrayList; import java.util.List; import java.util.Map; public class FundHoldings { public static void main(String[] args) throws Exception { // Read VOO's file (one GET, no key), naming your own project var request = HttpRequest.newBuilder( URI.create("https://tickerinside.com/api/v1/fund/voo.json")) .header("User-Agent", "MyProject/1.0 (+https://example.com)") .build(); var response = HttpClient.newHttpClient() .send(request, HttpResponse.BodyHandlers.ofString()); if (response.statusCode() != 200) { throw new RuntimeException("HTTP " + response.statusCode()); } JsonObject fund = JsonParser.parseString(response.body()) .getAsJsonObject(); // The date of the issuer's file the weights come from System.out.println("VOO holdings_as_of " + fund.get("holdings_as_of").getAsString()); // holdings maps each ticker to its weight in percent: largest first List> rows = new ArrayList<>(fund.getAsJsonObject("holdings").entrySet()); rows.sort((a, b) -> Double.compare( b.getValue().getAsDouble(), a.getValue().getAsDouble())); System.out.println(rows.size() + " holdings, largest first"); for (var row : rows) { System.out.println(row.getKey() + " " + row.getValue()); } // The line to print under any figure you quote System.out.println(fund.get("cite_as").getAsString()); } }