iothub-message-schema: twinChangeNotification

Chandra Mohan 461 Reputation points


I would like to know if there is a way to de-serialize data from the Azure function that is triggered when the reported property is updated in the IoT Hub Device Twin? Is there any schema or predefined class in EventData SDK that can be mapped to the EventData.Body?

// example code.
            public async void Run([IoTHubTrigger("messages/events", Connection = "iotConnection", ConsumerGroup = "functionapp")]EventData message, ILogger log)
    // iothub-message-schema: twinChangeNotification?
      var JsonString1 = Encoding.UTF8.GetString(message.Body.Array);

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,157 questions
{count} vote

Accepted answer
  1. QuantumCache 20,261 Reputation points

    Hello @Chandra Mohan ,

    There are many ways to de-serialize the dynamic Json object, below is one among them, please give a try and check if it works for you.

    dynamic stuff = JsonConvert.DeserializeObject(JsonString1);

            public static void Run([IoTHubTrigger("messages/events", Connection = "ConnectionString", ConsumerGroup = "funcgroup")]EventData message, ILogger log)  
                log.LogInformation($"C# IoT Hub trigger function processed a message: {Encoding.UTF8.GetString(message.Body.Array)}");  
                var JsonString1 = Encoding.UTF8.GetString(message.Body.Array);  
                dynamic stuff = JsonConvert.DeserializeObject(JsonString1);  


    Please visit the Azure IoT Samples-C-sharp for more info



0 additional answers

Sort by: Most helpful