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

已提问 2 年前1114 查看次数
1 回答
2
已接受的回答

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
专家
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则