2
votes

Following is my device twin payload, By mistake I have added "someKey" property to it.

{
   desired: {
      "state": {
           "processor": "running",
           "light": "on"
       },
       "someKey": "someValue"
   }
}

I want to remove permanently "someKey" property form JSON twin.

2

2 Answers

4
votes

To remove "someKey" from twin JSON

assign the null value to "someKey", then only it get removed from device twin JSON.

{
   desired: {
      "state": {
           "processor": "running",
           "light": "on"
       },
       "someKey": null
   }
}

So Next time onward you will receive JSON as below

{
   desired: {
      "state": {
           "processor": "running",
           "light": "on"
       }
   }
}
0
votes

From: https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-device-twins#back-end-operations

Device operations

Device operations

The device app operates on the device twin using the following atomic operations:

Partially update reported properties. This operation enables the partial update of the reported properties of the currently connected device. This operation uses the same JSON update format that the solution back end uses for a partial update of desired properties.

And then in Back-End operations

Partially update device twin. This operation enables the solution back end to partially update the tags or desired properties in a device twin. The partial update is expressed as a JSON document that adds or updates any property. Properties set to null are removed. The following example creates a new desired property with value {"newProperty": "newValue"}, overwrites the existing value of existingProperty with "otherNewValue", and removes otherOldProperty. No other changes are made to existing desired properties or tags:

{ "properties": { "desired": { "newProperty": { "nestedProperty": "newValue" }, "existingProperty": "otherNewValue", "otherOldProperty": null } } }

(...)