Looks like you have a JSON document as shown below:
{
"bpi": {
"2019-08-18": 9304.6179,
"2019-08-19": 9860.2835,
"2019-08-20": 9710.7164,
"2019-08-21": 9138.8615,
"2019-08-22": 9126.6978
}
}
As you seem to be using Java, you could use Jackson to parse the JSON document to an instance of a class such as:
@Data
public class ApiResponse {
private Map<LocalDate, BigDecimal> bpi;
}
Where the bpi
JSON property will be mapped to a Map<LocalDate, BigDecimal>
.
For parsing a JSON, you could have:
String json = ...;
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
ApiResponse apiResponse = mapper.readValue(json, ApiResponse.class);;
Then, to find the highest and the lowest values, you can use:
BigDecimal max = Collections.max(apiResponse.getBpi().values());
BigDecimal min = Collections.min(apiResponse.getBpi().values());
In case you need the full map entry, use:
Entry<LocalDate, BigDecimal> max =
Collections.max(apiResponse.getBpi().entrySet(), Entry.comparingByValue());
Entry<LocalDate, BigDecimal> min =
Collections.min(apiResponse.getBpi().entrySet(), Entry.comparingByValue());