I'm trying to merge two objects that has an array of objects in it. The two objects has different name/value pairs in the array:
"testobj1": {
"setting1":"text1",
"testarray": [
{
"name": "testname1",
"value": "testvalue1"
},
{
"name": "testname1",
"value": "testvalue1"
}
]
},
"testobj2": {
"setting2":"text2",
"testarray": [
{
"name": "newtestname",
"value": "newtestvalue"
}
]
}
I have looked at the documentation for the union function as many suggest, and read other posts like ARM Template concatenate object, but the result is that only the "testarray" from object 2 is kept. I was expecting:
"resultobj": {
"setting1":"text1",
"setting2":"text2",
"testarray": [
{
"name": "testname1",
"value": "testvalue1"
},
{
"name": "testname1",
"value": "testvalue1"
},
{
"name": "newtestname",
"value": "newtestvalue"
}
]
}
But i get:
"resultobj": {
"setting1":"text1",
"setting2":"text2",
"testarray": [
{
"name": "newtestname",
"value": "newtestvalue"
}
]
}
I know i can use concat to merge arrays, but can′t figure out how to merge these two objects to get the result i expect.
Here is the full template for test:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
"testobj1": {
"setting1": "text1",
"testarray": [
{
"name": "testname1",
"value": "testvalue1"
},
{
"name": "testname1",
"value": "testvalue1"
}
]
},
"testobj2": {
"setting2": "text2",
"testarray": [
{
"name": "newtestname",
"value": "newtestvalue"
}
]
}
},
"resources": [
],
"outputs": {
"testUnion": {
"type": "object",
"value": "[union(variables('testobj1'),variables('testobj2'))]"
},
"testConcat": {
"type": "array",
"value": "[concat(variables('testobj1').testarray,variables('testobj2').testarray)]"
}
}
}