|
2 | 2 | title: Template functions - objects
|
3 | 3 | description: Describes the functions to use in an Azure Resource Manager template (ARM template) for working with objects.
|
4 | 4 | ms.topic: conceptual
|
5 |
| -ms.date: 03/10/2022 |
| 5 | +ms.date: 05/09/2022 |
6 | 6 | ---
|
7 | 7 |
|
8 | 8 | # Object functions for ARM templates
|
@@ -163,6 +163,146 @@ The output from the preceding example with the default values is:
|
163 | 163 | | objectOutput | Object | {"one": "a", "three": "c"} |
|
164 | 164 | | arrayOutput | Array | ["two", "three"] |
|
165 | 165 |
|
| 166 | +## items |
| 167 | + |
| 168 | +`items(object)` |
| 169 | + |
| 170 | +Converts a dictionary object to an array. |
| 171 | + |
| 172 | +In Bicep, use the [items](../bicep/bicep-functions-object.md#items). |
| 173 | + |
| 174 | +### Parameters |
| 175 | + |
| 176 | +| Parameter | Required | Type | Description | |
| 177 | +|:--- |:--- |:--- |:--- | |
| 178 | +| object |Yes |object |The dictionary object to convert to an array. | |
| 179 | + |
| 180 | +### Return value |
| 181 | + |
| 182 | +An array of objects for the converted dictionary. Each object in the array has a `key` property that contains the key value for the dictionary. Each object also has a `value` property that contains the properties for the object. |
| 183 | + |
| 184 | +### Example |
| 185 | + |
| 186 | +The following example converts a dictionary object to an array. For each object in the array, it creates a new object with modified values. |
| 187 | + |
| 188 | +```json |
| 189 | +{ |
| 190 | + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", |
| 191 | + "contentVersion": "1.0.0.0", |
| 192 | + "variables": { |
| 193 | + "copy": [ |
| 194 | + { |
| 195 | + "name": "modifiedListOfEntities", |
| 196 | + "count": "[length(items(variables('entities')))]", |
| 197 | + "input": { |
| 198 | + "key": "[items(variables('entities'))[copyIndex('modifiedListOfEntities')].key]", |
| 199 | + "fullName": "[items(variables('entities'))[copyIndex('modifiedListOfEntities')].value.displayName]", |
| 200 | + "itemEnabled": "[items(variables('entities'))[copyIndex('modifiedListOfEntities')].value.enabled]" |
| 201 | + } |
| 202 | + } |
| 203 | + ], |
| 204 | + "entities": { |
| 205 | + "item002": { |
| 206 | + "enabled": false, |
| 207 | + "displayName": "Example item 2", |
| 208 | + "number": 200 |
| 209 | + }, |
| 210 | + "item001": { |
| 211 | + "enabled": true, |
| 212 | + "displayName": "Example item 1", |
| 213 | + "number": 300 |
| 214 | + } |
| 215 | + } |
| 216 | + }, |
| 217 | + "resources": [], |
| 218 | + "outputs": { |
| 219 | + "modifiedResult": { |
| 220 | + "type": "array", |
| 221 | + "value": "[variables('modifiedListOfEntities')]" |
| 222 | + } |
| 223 | + } |
| 224 | +} |
| 225 | +``` |
| 226 | + |
| 227 | +The preceding example returns: |
| 228 | + |
| 229 | +```json |
| 230 | +"modifiedResult": { |
| 231 | + "type": "Array", |
| 232 | + "value": [ |
| 233 | + { |
| 234 | + "fullName": "Example item 1", |
| 235 | + "itemEnabled": true, |
| 236 | + "key": "item001" |
| 237 | + }, |
| 238 | + { |
| 239 | + "fullName": "Example item 2", |
| 240 | + "itemEnabled": false, |
| 241 | + "key": "item002" |
| 242 | + } |
| 243 | + ] |
| 244 | +} |
| 245 | +``` |
| 246 | + |
| 247 | +The following example shows the array that is returned from the items function. |
| 248 | + |
| 249 | +```json |
| 250 | +{ |
| 251 | + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", |
| 252 | + "contentVersion": "1.0.0.0", |
| 253 | + "variables": { |
| 254 | + "entities": { |
| 255 | + "item002": { |
| 256 | + "enabled": false, |
| 257 | + "displayName": "Example item 2", |
| 258 | + "number": 200 |
| 259 | + }, |
| 260 | + "item001": { |
| 261 | + "enabled": true, |
| 262 | + "displayName": "Example item 1", |
| 263 | + "number": 300 |
| 264 | + } |
| 265 | + }, |
| 266 | + "entitiesArray": "[items(variables('entities'))]" |
| 267 | + }, |
| 268 | + "resources": [], |
| 269 | + "outputs": { |
| 270 | + "itemsResult": { |
| 271 | + "type": "array", |
| 272 | + "value": "[variables('entitiesArray')]" |
| 273 | + } |
| 274 | + } |
| 275 | +} |
| 276 | +``` |
| 277 | + |
| 278 | +The example returns: |
| 279 | + |
| 280 | +```json |
| 281 | +"itemsResult": { |
| 282 | + "type": "Array", |
| 283 | + "value": [ |
| 284 | + { |
| 285 | + "key": "item001", |
| 286 | + "value": { |
| 287 | + "displayName": "Example item 1", |
| 288 | + "enabled": true, |
| 289 | + "number": 300 |
| 290 | + } |
| 291 | + }, |
| 292 | + { |
| 293 | + "key": "item002", |
| 294 | + "value": { |
| 295 | + "displayName": "Example item 2", |
| 296 | + "enabled": false, |
| 297 | + "number": 200 |
| 298 | + } |
| 299 | + } |
| 300 | + ] |
| 301 | +} |
| 302 | +``` |
| 303 | + |
| 304 | +The items() function sorts the objects in the alphabetical order. For example, **item001** appears before **item002** in the outputs of the two preceding samples. |
| 305 | + |
166 | 306 | <a id="json"></a>
|
167 | 307 |
|
168 | 308 | ## json
|
|
0 commit comments