IoT Hub message routing query syntax

Arun Kumar 20 Reputation points


I have a 2D array as shown below in the message body received by IoT Hub.I have been trying various options in message routing query to check for the existence of the key "dioData" but nothing has worked so far.Pls suggest on how to check for the existence of the key "dioData" using message routing query.



 "dioData": [












Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,103 questions
0 comments No comments
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 13,301 Reputation points

    Hi @Arun Kumar Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    The IoTHub routing query syntax, although, is a SQL like language, offers limited set of functions and operations. To find the list of supported functions offered by IoTHub Query language, please refer to the section Functions of the article IoT Hub query language for device and module twins, jobs, and message routing

    Coming to your use case, since you are trying to validate a 2D dimensional array, you can leverage IS_ARRAY function to determine of the property dioData is of the expected format.

    For example, if the dioData is of the below format, the routing query IS_ARRAY($body.dioData) finds a match

    	"dioData" : [[1,1540,55597],[0.1483,18203]]

    Please note that the above query also matches an empty array such as {"dioData" : []}

    If you are certain that your property is a 2X3 matric, you can even enhance the routing query by testing the first row of the property. Here is the routing query syntax IS_ARRAY($body.dioData[0]). This checks if the first entry of the property is an array.

    For the IoTHub message routing to work, kindly ensure that the message should be in a JSON format and encoded in either UTF-8, UTF-16 or UTF-32. The contentType system property must be application/JSON.

    Here is a sample code in Python showing how I have formulated the data

    dio_data = [
        [1, 1540, 55597],
        [0, 1483, 18203]
    message_dict = {
        "dioData": dio_data
    message_json = json.dumps(message_dict)
    message = Message(message_json, content_encoding="utf-8", content_type="application/json")

    I have the routed query set to check the array validity of the first entry of the property as follows

    enter image description here

    I could see the message routed to the configured endpoint as expected.

    Hope this helps! If you need to perform more validations on the property, I appreciate it if you can share more details on your use case to help us provide more appropriate feedback.

    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments

0 additional answers

Sort by: Most helpful