A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-nested-queries.html below:

Nested object queries - AWS IoT Core

Nested object queries

You can use nested SELECT clauses to query for attributes within arrays and inner JSON objects. Supported by SQL version 2016-03-23 and later.

Consider the following MQTT message:

{ 
    "e": [
        { "n": "temperature", "u": "Cel", "t": 1234, "v": 22.5 },
        { "n": "light", "u": "lm", "t": 1235, "v": 135 },
        { "n": "acidity", "u": "pH", "t": 1235, "v": 7 }
    ]
}
Example

You can convert values to a new array with the following rule.

SELECT (SELECT VALUE n FROM e) as sensors FROM 'my/topic'

The rule generates the following output.

{
    "sensors": [
        "temperature",
        "light",
        "acidity"
    ]
}
Example

Using the same MQTT message, you can also query a specific value within a nested object with the following rule.

SELECT (SELECT v FROM e WHERE n = 'temperature') as temperature FROM 'my/topic'

The rule generates the following output.

{
    "temperature": [
        {
            "v": 22.5
        }
    ]
}
Example

You can also flatten the output with a more complicated rule.

SELECT get((SELECT v FROM e WHERE n = 'temperature'), 0).v as temperature FROM 'topic'

The rule generates the following output.

{
    "temperature": 22.5
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4