AWS IoT rule SQL query for mqtt nested arrays

0

I have the following mqtt message:

{
  "sensors": [
    {
      "lsid": 412618,
      "data": [
        {
          "temp_in": 72.3,
          "heat_index_in": 72,
          "dew_point_in": 55.9,
          "ts": 1652785241,
          "hum_in": 56.3
        }
      ],
      "sensor_type": 243,
      "data_structure_type": 12
    },
    {
      "lsid": 421195,
}

I can get the "sensors,0.lsid" value and the entire "data" array using this query:

 select get(sensors,0).lsid as ls, get(sensors, 0).data as data1 from "topic"

but what I really need is to get "temp_in:72.3" , i.e. the values from the second level array I've tried using this :https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-nested-queries.html, but unless i'm not following it correctly, it doesnt seem to work.

Any help would be greatly appreciated

asked 2 years ago1099 views
1 Answer
2
Accepted Answer

You can nest get() function calls as in:

select get(sensors,0).lsid as ls, get(get(sensors,0).data, 0).temp_in as temp_in from "topic"

AWS
EXPERT
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions