Basically, I am creating a complex JSON Object variable, two of them actually. One to form the body of an HTTP response to the calling app and another to by the body of a POST to an API. The complex JSON object has boolean properties, arrays, and nested object. I have a lot of property setting to do. What I am finding is that I have to do a Compose action on the current state of the object, then do a Set Variable action to set the variable to the output of the Compose action. Basically, two actions for each and every property update. Am I missing something? Is it possible to set the property on a JSON object with only one Action and not two?
Here is the code of a simple Logic App showing the two step process of two Actions to update a single property:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Check_Compose_result_shows_array_is_still_empty": {
"inputs": {
"name": "temp",
"value": "@{first(variables('JsonObj').apiUrls)}"
},
"runAfter": {
"Compose_into_an_array": [
"Succeeded"
]
},
"type": "SetVariable"
},
"Check_that_bool_property_was_changed": {
"inputs": {
"name": "temp",
"value": "@{variables('JsonObj').success}"
},
"runAfter": {
"Set_variable": [
"Succeeded"
]
},
"type": "SetVariable"
},
"Compose_into_an_array": {
"inputs": "@setProperty(variables('JsonObj'),'apiUrls',union(variables('JsonObj').apiUrls,json('[''http//:apiBaseUrl/EDI/containers/defaults'']')))",
"runAfter": {
"Initialize_JSON_Object_variable": [
"Succeeded"
]
},
"type": "Compose"
},
"Compose_to_set_bool_property": {
"inputs": "@setProperty(variables('JsonObj'),'success',true)",
"runAfter": {
"Set_variable_to_retain_Compose_output": [
"Succeeded"
]
},
"type": "Compose"
},
"Initialize_JSON_Object_variable": {
"inputs": {
"variables": [
{
"name": "JsonObj",
"type": "Object",
"value": "@json(concat('{ ''success'': false, ''apiUrls'': [], ''workFlow'': ',workflow(),'}'))"
}
]
},
"runAfter": {
"Initialize_temp_variable_": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_temp_variable_": {
"inputs": {
"variables": [
{
"name": "temp",
"type": "String"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Set_variable": {
"inputs": {
"name": "JsonObj",
"value": "@outputs('Compose_to_set_bool_property')"
},
"runAfter": {
"Compose_to_set_bool_property": [
"Succeeded"
]
},
"type": "SetVariable"
},
"Set_variable_to_retain_Compose_output": {
"inputs": {
"name": "JsonObj",
"value": "@outputs('Compose_into_an_array')"
},
"runAfter": {
"Check_Compose_result_shows_array_is_still_empty": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
}
}