Parse JSON data


#1

I am trying to parse JSON data, I have reviewed a few posts, but I think they are “further” along than I am, I need to understand the “basics” of it first. The data is coming from a weather station (Weather Flow Tempest). They have an API that will give JSON data.

When I go to the URL of my API into a web browser, it returns the following:


{“status”:{“status_code”:0,“status_message”:“SUCCESS”},“device_id”:120809,“type”:“obs_st”,“source”:“cache”,“summary”:{“pressure_trend”:“rising”,“strike_count_1h”:7,“strike_count_3h”:59,“precip_total_1h”:0.0,“strike_last_dist”:36,“strike_last_epoch”:1623277854,“precip_accum_local_yesterday”:9.347867,“precip_accum_local_yesterday_final”:5.600681,“precip_analysis_type_yesterday”:1,“feels_like”:25.3,“heat_index”:25.3,“wind_chill”:25.3},“obs”:[[1623278933,0,0,0,0,3,1011.9,25.3,95,6621,0.61,55,0,0,0,0,2.69,1,8.096712,null,null,0]]}


I understand that I have to use the do Make a GET request to the URL. But I am just not sure of what I am supposed to do next and how to “use” any of the data that was received.

I know that this is asking a lot at this point because I have so little of an understanding of what to do next, but I think that if I could get pointed in the right direction, I might be able to figure the rest out. Any help is greatly appreciated.

Thank you in advance.


#2

I haven’t done this for a long while, but as I recall, the response to your web request should appear in the $response variable and it is assumed to be in JSON format so you don’t have to do any specific conversion. So you should be able to access the results using e.g. $response.status.status_message, $response.obs[0][0] etc.


#3

I concur, webCore does automatically parse JSON data into the $response variable accessible using an expression as mentioned above $response.status.status_message

I would only add that the $response variable is only valid during that one execution of the piston, it will read as null at all other times.

My general process is to set the variable first then proceed with any data processing.


#4

Great. Thank you both. I will try playing around with this tonight when I am home!