IoT Rules SELECT Property with name "0"

55 views Asked by At

Really struggling with selecting values in IoT Rules.

My input looks like this, and I have no control over the data coming in:

"data": {
        "antennas": {
            "1": "disconnected",
            "2": "connected",
            "3": "disconnected",
            "4": "connected"
        }
}

What I'd like to achieve is the select statement transform the above into:

{
  antenna_1: "disconnected",
  antenna_2: "connected",
  antenna_3: "disconnected",
  antenna_4: "connected"
}

I've tried:

SELECT data.antennas.1 as antenna_1 FROM ...

SELECT [data.antennas.1] as antenna_1 FROM ...

SELECT data.antennas[1] as antenna_1 FROM ...

SELECT data.antennas.[1] as antenna_1 FROM ...

SELECT data.antennas['1'] as antenna_1 FROM ...

SELECT `data.antennas.1` as antenna_1 FROM ...

But nothing seems to work... :'-(

1

There are 1 answers

3
brushtakopo On BEST ANSWER

Here is a working IoT SQL statement using get function (tested using SQL version 2026-03-23):

SELECT 
get(get(get(*,"data"),"antennas"),"1") as antenna_1,
get(get(get(*,"data"),"antennas"),"2") as antenna_2,
get(get(get(*,"data"),"antennas"),"3") as antenna_3,
get(get(get(*,"data"),"antennas"),"4") as antenna_4

FROM 'your/topic'