Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Nested object queries

Focus mode
Nested object queries - AWS IoT Core

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 }
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.