Dan Benitah

Using tags with Azure Digital Twins

The latest version Azure Digital Twins' DTDL (Digital Twin Definition Language v2) supports a wide variety of schemas.

One of them is the ability to add tags using a Map.

The documentation found here shows you how to leverage the Map type to add marker or value tags.

The following in the case of a value tag.

{"@type": "Property","name": "tags","schema": {
    "@type": "Map",
    "mapKey": {
      "name": "tagName",
      "schema": "string"
    },
    "mapValue": {
      "name": "tagValue",
      "schema": "string"
    }}
}

... but I did not easily find examples of how to create new twins in code using these more complex schemas (Map, Array, Enum, object).

So to stay on the example from the Microsoft's documentation, to add tags using the Map schema, you can create a Dictionary<string, string> to add tags to your metadata as follows.

myTwinMetadata.Add($"tags", new Dictionary<string, string>() { { "red", "" }, { "size", "large" } });

What would or do you use the tags for?

Feel free to message on twitter to let me know...


Dan Benitah

Written by Dan Benitah, London, UK.