Skip to content

Commit 9413fbe

Browse files
Merge pull request #263024 from mumian/0103-union-deep
Add the deep merge capability information.
2 parents 126a54c + 8735d9f commit 9413fbe

File tree

4 files changed

+268
-8
lines changed

4 files changed

+268
-8
lines changed

articles/azure-resource-manager/bicep/bicep-functions-array.md

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
---
22
title: Bicep functions - arrays
33
description: Describes the functions to use in a Bicep file for working with arrays.
4-
author: mumian
54
ms.topic: conceptual
65
ms.custom: devx-track-bicep
7-
ms.author: jgao
8-
ms.date: 12/09/2022
6+
ms.date: 01/11/2024
97
---
108

119
# Array functions for Bicep
@@ -949,6 +947,8 @@ For arrays, the function iterates through each element in the first parameter an
949947

950948
For objects, property names and values from the first parameter are added to the result. For later parameters, any new names are added to the result. If a later parameter has a property with the same name, that value overwrites the existing value. The order of the properties isn't guaranteed.
951949

950+
The union function merges not only the top-level elements but also recursively merges any nested objects within them. Nested array values are not merged. See the second example in the following section.
951+
952952
### Example
953953

954954
The following example shows how to use union with arrays and objects:
@@ -989,6 +989,63 @@ The output from the preceding example with the default values is:
989989
| objectOutput | Object | {"one": "a", "two": "b", "three": "c2", "four": "d", "five": "e"} |
990990
| arrayOutput | Array | ["one", "two", "three", "four"] |
991991

992+
The following example shows the deep merge capability:
993+
994+
```bicep
995+
var firstObject = {
996+
property: {
997+
one: 'a'
998+
two: 'b'
999+
three: 'c1'
1000+
}
1001+
nestedArray: [
1002+
1
1003+
2
1004+
]
1005+
}
1006+
var secondObject = {
1007+
property: {
1008+
three: 'c2'
1009+
four: 'd'
1010+
five: 'e'
1011+
}
1012+
nestedArray: [
1013+
3
1014+
4
1015+
]
1016+
}
1017+
var firstArray = [
1018+
[
1019+
'one'
1020+
'two'
1021+
]
1022+
[
1023+
'three'
1024+
]
1025+
]
1026+
var secondArray = [
1027+
[
1028+
'three'
1029+
]
1030+
[
1031+
'four'
1032+
'two'
1033+
]
1034+
]
1035+
1036+
output objectOutput object = union(firstObject, secondObject)
1037+
output arrayOutput array = union(firstArray, secondArray)
1038+
```
1039+
1040+
The output from the preceding example is:
1041+
1042+
| Name | Type | Value |
1043+
| ---- | ---- | ----- |
1044+
| objectOutput | Object |{"property":{"one":"a","two":"b","three":"c2","four":"d","five":"e"},"nestedArray":[3,4]}|
1045+
| arrayOutput | Array |[["one","two"],["three"],["four","two"]]|
1046+
1047+
If nested arrays were merged, then the value of **objectOutput.nestedArray** would be [1, 2, 3, 4], and the value of **arrayOutput** would be [["one", "two", "three"], ["three", "four", "two"]].
1048+
9921049
## Next steps
9931050

9941051
* To get an array of string values delimited by a value, see [split](./bicep-functions-string.md#split).

articles/azure-resource-manager/bicep/bicep-functions-object.md

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
---
22
title: Bicep functions - objects
33
description: Describes the functions to use in a Bicep file for working with objects.
4-
author: mumian
5-
ms.author: jgao
64
ms.topic: conceptual
75
ms.custom: devx-track-bicep
8-
ms.date: 03/19/2023
6+
ms.date: 01/11/2024
97
---
108

119
# Object functions for Bicep
@@ -415,6 +413,8 @@ For arrays, the function iterates through each element in the first parameter an
415413

416414
For objects, property names and values from the first parameter are added to the result. For later parameters, any new names are added to the result. If a later parameter has a property with the same name, that value overwrites the existing value. The order of the properties isn't guaranteed.
417415

416+
The union function merges not only the top-level elements but also recursively merges any nested objects within them. Nested array values are not merged. See the second example in the following section.
417+
418418
### Example
419419

420420
The following example shows how to use union with arrays and objects:
@@ -455,6 +455,63 @@ The output from the preceding example with the default values is:
455455
| objectOutput | Object | {"one": "a", "two": "b", "three": "c2", "four": "d", "five": "e"} |
456456
| arrayOutput | Array | ["one", "two", "three", "four"] |
457457

458+
The following example shows the deep merge capability:
459+
460+
```bicep
461+
var firstObject = {
462+
property: {
463+
one: 'a'
464+
two: 'b'
465+
three: 'c1'
466+
}
467+
nestedArray: [
468+
1
469+
2
470+
]
471+
}
472+
var secondObject = {
473+
property: {
474+
three: 'c2'
475+
four: 'd'
476+
five: 'e'
477+
}
478+
nestedArray: [
479+
3
480+
4
481+
]
482+
}
483+
var firstArray = [
484+
[
485+
'one'
486+
'two'
487+
]
488+
[
489+
'three'
490+
]
491+
]
492+
var secondArray = [
493+
[
494+
'three'
495+
]
496+
[
497+
'four'
498+
'two'
499+
]
500+
]
501+
502+
output objectOutput object = union(firstObject, secondObject)
503+
output arrayOutput array = union(firstArray, secondArray)
504+
```
505+
506+
The output from the preceding example is:
507+
508+
| Name | Type | Value |
509+
| ---- | ---- | ----- |
510+
| objectOutput | Object |{"property":{"one":"a","two":"b","three":"c2","four":"d","five":"e"},"nestedArray":[3,4]}|
511+
| arrayOutput | Array |[["one","two"],["three"],["four","two"]]|
512+
513+
If nested arrays were merged, then the value of **objectOutput.nestedArray** would be [1, 2, 3, 4], and the value of **arrayOutput** would be [["one", "two", "three"], ["three", "four", "two"]].
514+
458515
## Next steps
459516

460517
* For a description of the sections in a Bicep file, see [Understand the structure and syntax of Bicep files](./file.md).

articles/azure-resource-manager/templates/template-functions-array.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Template functions - arrays
33
description: Describes the functions to use in an Azure Resource Manager template (ARM template) for working with arrays.
44
ms.topic: conceptual
55
ms.custom: devx-track-arm-template
6-
ms.date: 05/22/2023
6+
ms.date: 01/11/2024
77
---
88

99
# Array functions for ARM templates
@@ -721,6 +721,8 @@ For arrays, the function iterates through each element in the first parameter an
721721

722722
For objects, property names and values from the first parameter are added to the result. For later parameters, any new names are added to the result. If a later parameter has a property with the same name, that value overwrites the existing value. The order of the properties isn't guaranteed.
723723

724+
The union function merges not only the top-level elements but also recursively merges any nested objects within them. Nested array values are not merged. See the second example in the following section.
725+
724726
### Example
725727

726728
The following example shows how to use union with arrays and objects.
@@ -734,6 +736,77 @@ The output from the preceding example with the default values is:
734736
| objectOutput | Object | {"one": "a", "two": "b", "three": "c2", "four": "d", "five": "e"} |
735737
| arrayOutput | Array | ["one", "two", "three", "four"] |
736738

739+
The following example shows the deep merge capability:
740+
741+
```json
742+
{
743+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
744+
"contentVersion": "1.0.0.0",
745+
"variables": {
746+
"firstObject": {
747+
"property": {
748+
"one": "a",
749+
"two": "b",
750+
"three": "c1"
751+
},
752+
"nestedArray": [
753+
1,
754+
2
755+
]
756+
},
757+
"secondObject": {
758+
"property": {
759+
"three": "c2",
760+
"four": "d",
761+
"five": "e"
762+
},
763+
"nestedArray": [
764+
3,
765+
4
766+
]
767+
},
768+
"firstArray": [
769+
[
770+
"one",
771+
"two"
772+
],
773+
[
774+
"three"
775+
]
776+
],
777+
"secondArray": [
778+
[
779+
"three"
780+
],
781+
[
782+
"four",
783+
"two"
784+
]
785+
]
786+
},
787+
"resources": [],
788+
"outputs": {
789+
"objectOutput": {
790+
"type": "Object",
791+
"value": "[union(variables('firstObject'), variables('secondObject'))]"
792+
},
793+
"arrayOutput": {
794+
"type": "Array",
795+
"value": "[union(variables('firstArray'), variables('secondArray'))]"
796+
}
797+
}
798+
}
799+
```
800+
801+
The output from the preceding example is:
802+
803+
| Name | Type | Value |
804+
| ---- | ---- | ----- |
805+
| objectOutput | Object |{"property":{"one":"a","two":"b","three":"c2","four":"d","five":"e"},"nestedArray":[3,4]}|
806+
| arrayOutput | Array |[["one","two"],["three"],["four","two"]]|
807+
808+
If nested arrays were merged, then the value of **objectOutput.nestedArray** would be [1, 2, 3, 4], and the value of **arrayOutput** would be [["one", "two", "three"], ["three", "four", "two"]].
809+
737810
## Next steps
738811

739812
* For a description of the sections in an ARM template, see [Understand the structure and syntax of ARM templates](./syntax.md).

articles/azure-resource-manager/templates/template-functions-object.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Template functions - objects
33
description: Describes the functions to use in an Azure Resource Manager template (ARM template) for working with objects.
44
ms.topic: conceptual
55
ms.custom: devx-track-arm-template
6-
ms.date: 08/22/2023
6+
ms.date: 01/11/2024
77
---
88

99
# Object functions for ARM templates
@@ -437,6 +437,8 @@ For arrays, the function iterates through each element in the first parameter an
437437

438438
For objects, property names and values from the first parameter are added to the result. For later parameters, any new names are added to the result. If a later parameter has a property with the same name, that value overwrites the existing value. The order of the properties isn't guaranteed.
439439

440+
The union function merges not only the top-level elements but also recursively merging any nested arrays and objects within them. See the second example in the following section.
441+
440442
### Example
441443

442444
The following example shows how to use union with arrays and objects:
@@ -450,6 +452,77 @@ The output from the preceding example with the default values is:
450452
| objectOutput | Object | {"one": "a", "two": "b", "three": "c2", "four": "d", "five": "e"} |
451453
| arrayOutput | Array | ["one", "two", "three", "four"] |
452454

455+
The following example shows the deep merge capability:
456+
457+
```json
458+
{
459+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
460+
"contentVersion": "1.0.0.0",
461+
"variables": {
462+
"firstObject": {
463+
"property": {
464+
"one": "a",
465+
"two": "b",
466+
"three": "c1"
467+
},
468+
"nestedArray": [
469+
1,
470+
2
471+
]
472+
},
473+
"secondObject": {
474+
"property": {
475+
"three": "c2",
476+
"four": "d",
477+
"five": "e"
478+
},
479+
"nestedArray": [
480+
3,
481+
4
482+
]
483+
},
484+
"firstArray": [
485+
[
486+
"one",
487+
"two"
488+
],
489+
[
490+
"three"
491+
]
492+
],
493+
"secondArray": [
494+
[
495+
"three"
496+
],
497+
[
498+
"four",
499+
"two"
500+
]
501+
]
502+
},
503+
"resources": [],
504+
"outputs": {
505+
"objectOutput": {
506+
"type": "Object",
507+
"value": "[union(variables('firstObject'), variables('secondObject'))]"
508+
},
509+
"arrayOutput": {
510+
"type": "Array",
511+
"value": "[union(variables('firstArray'), variables('secondArray'))]"
512+
}
513+
}
514+
}
515+
```
516+
517+
The output from the preceding example is:
518+
519+
| Name | Type | Value |
520+
| ---- | ---- | ----- |
521+
| objectOutput | Object |{"property":{"one":"a","two":"b","three":"c2","four":"d","five":"e"},"nestedArray":[3,4]}|
522+
| arrayOutput | Array |[["one","two"],["three"],["four","two"]]|
523+
524+
If nested arrays were merged, then the value of **objectOutput.nestedArray** would be [1, 2, 3, 4], and the value of **arrayOutput** would be [["one", "two", "three"], ["three", "four", "two"]].
525+
453526
## Next steps
454527

455528
* For a description of the sections in an ARM template, see [Understand the structure and syntax of ARM templates](./syntax.md).

0 commit comments

Comments
 (0)