Rules and Expressions with Open Weather API

Based on their sample data, it looks like the current weather is nested within an array.

{
  "lat": 39.31,
  "lon": -74.5,
  "timezone": "America/New_York",
  "timezone_offset": -18000,
  "current": {
    "dt": 1646318698,
    "sunrise": 1646306882,
    "sunset": 1646347929,
    "temp": 282.21,
    "feels_like": 278.41,
    "pressure": 1014,
    "humidity": 65,
    "dew_point": 275.99,
    "uvi": 2.55,
    "clouds": 40,
    "visibility": 10000,
    "wind_speed": 8.75,
    "wind_deg": 360,
    "wind_gust": 13.89,
    "weather": [
      {
        "id": 802,
        "main": "Clouds",
        "description": "scattered clouds",
        "icon": "03d"
      }
    ]
  },

Notice that immediately after "weather": there is a [ which indicates an array. That means you would need something like the following to grab the first array item.

$context.response.data.current.weather.0.description

Like the above, the 0 is referring to the position of the item within the array. Arrays start at ‘0’ rather than ‘1’. You can find more details on how properties are accessed from objects in this thread.

1 Like