Azure Resource Tags in JSON Format

This is a quick one: We all know that using Azure Resource Tags is a key element in a company’s governance strategy. Tags are used on resources to ensure you stay in control (e.g. to set an owner, department or environment), for cost management (e.g. to configure a cost center or customer) or any other purposes. Resource tags come with some limitations and it’s important to understand those. One of these limitations is the max. number of tags per resource which by the time of writing is 15. Using JSON-formatted tag values can help companies to overcome this limit.

Tags are name/value pairs. A simple trick to store more or more complex values is to use a JSON-formatted string. That allows to store much more tags and also gives you additional flexibility. Let’s use a “CostCenter” tag as a simple example here. Imagine you want to split costs of a resource between 2 or more different cost centers. using tags. You can easily solve this by using a JSON-formatted value and store two cost center objects in an array.

Name: CostCenter

Value: [{“1”: {“CostCenter”: 123,”Percentage”: 80},”2″: {“CostCenter”: 456,”Percentage”: 20}}]


Once needed, you can extract the JSON-string and use the name/values from the array in your billing procedure (or for whatever you want to use the data). Using the Azure CLI you can easily access the tags of a resource.

$resource = az resource list –query “[?name==’w-agw-iis-01′]” | convertfrom-json


$resource.tags.costcenter | convertfrom-json

($resource.tags.costcenter | convertfrom-json).1


Happy tagging!
Cheers, Marcel

About Marcel Zehner

Microsoft Azure MVP
This entry was posted in Azure and tagged , , , , , , . Bookmark the permalink.

2 Responses to Azure Resource Tags in JSON Format

  1. Amit says:

    Awesome idea to help resources categorized as per business logics and consolidated tags

  2. Joao Rosa says:

    One important remark is the fact that tag values are limited to 256 characters, thus it is important not to accumulate a ton of information within the same tag or the character limit can easily blow up.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s