@@ -4,7 +4,7 @@ description: Describes the lambda functions to use in an Azure Resource Manager
4
4
author : mumian
5
5
ms.topic : conceptual
6
6
ms.author : jgao
7
- ms.date : 02/06 /2023
7
+ ms.date : 02/07 /2023
8
8
---
9
9
10
10
# Lambda functions for ARM templates
@@ -48,7 +48,7 @@ An array.
48
48
49
49
### Examples
50
50
51
- The following examples show how to use the filter function.
51
+ The following examples show how to use the ` filter ` function.
52
52
53
53
``` json
54
54
{
@@ -160,7 +160,7 @@ An array.
160
160
161
161
### Example
162
162
163
- The following example shows how to use the map function.
163
+ The following example shows how to use the ` map ` function.
164
164
165
165
``` json
166
166
{
249
249
250
250
### Example
251
251
252
- The following examples show how to use the reduce function.
252
+ The following examples show how to use the ` reduce ` function.
253
253
254
254
``` json
255
255
{
@@ -355,7 +355,7 @@ An array.
355
355
356
356
### Example
357
357
358
- The following example shows how to use the sort function.
358
+ The following example shows how to use the ` sort ` function.
359
359
360
360
``` json
361
361
{
@@ -410,6 +410,156 @@ The output from the preceding example sorts the dog objects from the youngest to
410
410
| ---- | ---- | ----- |
411
411
| dogsByAge | Array | [ {"name":"Indy","age":2,"interests":[ "Butter"] },{"name":"Casper","age":3,"interests":[ "Other dogs"] },{"name":"Evie","age":5,"interests":[ "Ball","Frisbee"] },{"name":"Kira","age":8,"interests":[ "Rubs"] }] |
412
412
413
+ ## toObject
414
+
415
+ ` toObject(inputArray, lambda expression, [lambda expression]) `
416
+
417
+ Converts an array to an object with a custom key function and optional custom value function.
418
+
419
+ In Bicep, use the [ toObject] ( ../bicep/bicep-functions-lambda.md#toobject ) function.
420
+
421
+ ### Parameters
422
+
423
+ | Parameter | Required | Type | Description |
424
+ | :--- | :--- | :--- | :--- |
425
+ | inputArray | Yes | array | The array used for creating an object.|
426
+ | lambda expression | Yes | expression | The lambda expression used to provide the key predicate.|
427
+ | lambda expression | No | expression | The lambda expression used to provide the value predicate.|
428
+
429
+ ### Return value
430
+
431
+ An object.
432
+
433
+ ### Example
434
+
435
+ The following example shows how to use the ` toObject ` function with the two required parameters:
436
+
437
+ ``` json
438
+ {
439
+ "$schema" : " https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#" ,
440
+ "contentVersion" : " 1.0.0.0" ,
441
+ "variables" : {
442
+ "dogs" : [
443
+ {
444
+ "name" : " Evie" ,
445
+ "age" : 5 ,
446
+ "interests" : [
447
+ " Ball" ,
448
+ " Frisbee"
449
+ ]
450
+ },
451
+ {
452
+ "name" : " Casper" ,
453
+ "age" : 3 ,
454
+ "interests" : [
455
+ " Other dogs"
456
+ ]
457
+ },
458
+ {
459
+ "name" : " Indy" ,
460
+ "age" : 2 ,
461
+ "interests" : [
462
+ " Butter"
463
+ ]
464
+ },
465
+ {
466
+ "name" : " Kira" ,
467
+ "age" : 8 ,
468
+ "interests" : [
469
+ " Rubs"
470
+ ]
471
+ }
472
+ ]
473
+ },
474
+ "resources" : {},
475
+ "outputs" : {
476
+ "dogsObject" : {
477
+ "type" : " object" ,
478
+ "value" : " [toObject(variables('dogs'), lambda('entry', lambdaVariables('entry').name))]"
479
+ }
480
+ }
481
+ }
482
+ ```
483
+
484
+ The preceding example generates an object based on an array.
485
+
486
+ | Name | Type | Value |
487
+ | ---- | ---- | ----- |
488
+ | dogsObject | Object | {"Evie":{"name":"Evie","age":5,"interests":[ "Ball","Frisbee"] },"Casper":{"name":"Casper","age":3,"interests":[ "Other dogs"] },"Indy":{"name":"Indy","age":2,"interests":[ "Butter"] },"Kira":{"name":"Kira","age":8,"interests":[ "Rubs"] }} |
489
+
490
+ The following ` toObject ` function provides the same output.
491
+
492
+ ``` json
493
+ "outputs" : {
494
+ "dogsObject" : {
495
+ "type" : " object" ,
496
+ "value" : " [toObject(variables('dogs'), lambda('entry', lambdaVariables('entry').name), lambda('entry', lambdaVariables('entry')))]"
497
+ }
498
+ }```
499
+
500
+ The following example shows how to use the `toObject` function with three parameters.
501
+
502
+ ```json
503
+ {
504
+ "$schema" : " https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#" ,
505
+ "contentVersion" : " 1.0.0.0" ,
506
+ "variables" : {
507
+ "dogs" : [
508
+ {
509
+ "name" : " Evie" ,
510
+ "properties" : {
511
+ "age" : 5 ,
512
+ "interests" : [
513
+ " Ball" ,
514
+ " Frisbee"
515
+ ]
516
+ }
517
+ },
518
+ {
519
+ "name" : " Casper" ,
520
+ "properties" : {
521
+ "age" : 3 ,
522
+ "interests" : [
523
+ " Other dogs"
524
+ ]
525
+ }
526
+ },
527
+ {
528
+ "name" : " Indy" ,
529
+ "properties" : {
530
+ "age" : 2 ,
531
+ "interests" : [
532
+ " Butter"
533
+ ]
534
+ }
535
+ },
536
+ {
537
+ "name" : " Kira" ,
538
+ "properties" : {
539
+ "age" : 8 ,
540
+ "interests" : [
541
+ " Rubs"
542
+ ]
543
+ }
544
+ }
545
+ ]
546
+ },
547
+ "resources" : {},
548
+ "outputs" : {
549
+ "dogsObject" : {
550
+ "type" : " object" ,
551
+ "value" : " [toObject(variables('dogs'), lambda('entry', lambdaVariables('entry').name), lambda('entry', lambdaVariables('entry').properties))]"
552
+ }
553
+ }
554
+ }
555
+ ```
556
+
557
+ The preceding example generates an object based on an array.
558
+
559
+ | Name | Type | Value |
560
+ | ---- | ---- | ----- |
561
+ | dogsObject | Object | {"Evie":{"age":5,"interests":[ "Ball","Frisbee"] },"Casper":{"age":3,"interests":[ "Other dogs"] },"Indy":{"age":2,"interests":[ "Butter"] },"Kira":{"age":8,"interests":[ "Rubs"] }} |
562
+
413
563
## Next steps
414
564
415
565
- See [ Template functions - arrays] ( ./template-functions-array.md ) for additional array related template functions.
0 commit comments