Problem with returned json

I’m starting a project using JAVA. When I use… https://swd.weatherflow.com/swd/rest/observations/device/{device_id}
the returned json has double starting and ending array brackets in the ‘obs’ object… []. When I try to parse this json I always get an error message. Is there an issue here? I’ve come up with a clumsy hack using string functions to overcome this and replace the double brackets with single brackets but I wonder if there is a problem with the request response on Tempest’s end.

1 Like

It would likely be helpful to include the request and the verbatim response you are getting in order to troubleshoot this.

Double brackets is just an array of arrays so you would parse it as such.

1 Like

Thanks for responding..,
This is my HttpRequest…

HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("[https://swd.weatherflow.com/swd/rest/stats/station/](https://swd.weatherflow.com/swd/rest/stats/station/)" + my_station_id + "?api_key=" + my_access_key))
        .header("accept", "application/json")
        .method("GET", HttpRequest.BodyPublishers.noBody())
        .build();
HttpResponse<String> response = null;
try {
    response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
} catch (IOException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
}
-------------------------------------------------------------------
This is the response...
{"status":{"status_code":0,"status_message":"SUCCESS"},"device_id":378803,"type":"obs_st","summary":{"pressure_trend":"steady","strike_count_1h":0,"strike_count_3h":0,"precip_total_1h":0.0,"strike_last_dist":42,"strike_last_epoch":1735705542,"precip_accum_local_yesterday":12.033536,"precip_accum_local_yesterday_final":6.787493,"precip_analysis_type_yesterday":1,"feels_like":9.4,"heat_index":9.4,"wind_chill":9.4},"obs":[[1742911151,0.4,1.2,1.9,324,6,1008.5,9.4,49,34161,1.51,285,0.0,0,0,0,2.61,1,0.0,0.0,0.0,0]]}

Note the double array brackets... I wasn't able to parse this json until I altered this string to
replace the double brackets with single brackets. I'm not a professional developer... maybe I just don't understand json well enough.
Thanks,
Rudy




You may want to check the JSON parser you are using - that response is indeed valid. You can paste it into something like https://jsonlint.com or https://jsonchecker.com/ to confirm as well.

If you’d like, perhaps post the code setting up the parser you’re using along with how you’re setting any configuration options? The problem may be there-

The problem that you are encountering is that the original API was written to return an array of arrays for obs values to allow for observation catch-ups in one request if there was a backlog. I added spaces below to make an example more readable:

[ [obs_array0] [obs_array1] [obs_array2] ]

Proper programming would iterate the returned obs array and process each sub-array, but I honestly don’t recall ever seeing more than one sub-array returned at least in the UDP API that uses the same format.

I don’t know JAVA, but something like obs[0] would be the Python way of getting the first sub-array without having to go to a string and delete the outside array [ ] characters…

2 Likes