Working with weather station data JSON

What is the best way to pull say the temperature out of this JSON object and drop it into msg.payload. So far the examples I have found are more down the line of multiple devices all sending temperature and separating out the separate devices.

{"observations":[{"stationID":"ISTORE","obsTimeUtc":"2023-02-09T04:20:01Z","obsTimeLocal":"2023-02-08 22:20:01","neighborhood":"Ste. Anne","softwareType":"AMBWeatherV4.2.6","country":"CA","solarRadiation":0.2,"lon":-76.08,"realtimeFrequency":null,"epoch":16401,"lat":47.633,"uv":0,"winddir":10,"humidity":96,"qcStatus":-1,"imperial":{"temp":30,"heatIndex":30,"dewpt":30,"windChill":26,"windSpeed":5,"windGust":6,"pressure":29.02,"precipRate":0,"precipTotal":0.03,"elev":247}}]}

The documentation describes how to work with messages.

Feed the data into a debug node, then you can explore it's structure.
There is a "Copy path" button which in this example gives "payload.observations[0].imperial.temp"

1 Like

I hadn't realized this earlier.

I built a function node with

var temp = msg.payload.observations[0].imperial.temp

msg.payload = temp;
return msg;

in hopes that it would change the new payload to the temperature. In stead it give an error

TypeError: Cannot read properties of undefined (reading '0')

EDIT: This does work my wire was to the wrong place.

Ok I got it, it works as expected. I looked closer and the wire was direct from the inject node and not going through the http request node.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.