【发布时间】:2018-03-13 10:06:47
【问题描述】:
基本上,我正在创建一个复杂的 JSON 对象变量,实际上是其中两个。一个形成对调用应用程序的 HTTP 响应的主体,另一个形成对 API 的 POST 的主体。复杂的 JSON 对象具有布尔属性、数组和嵌套对象。我有很多属性设置要做。我发现我必须对对象的当前状态执行 Compose 操作,然后执行 Set Variable 操作以将变量设置为 Compose 操作的输出。基本上,每个属性更新都有两个操作。我错过了什么吗?是否可以仅使用一个 Action 而不是两个 Action 在 JSON 对象上设置属性?
这是一个简单逻辑应用程序的代码,显示了两个操作更新单个属性的两步过程:
{
"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"
}
}
}
}
【问题讨论】:
-
为什么不使用 Liquid Map?
标签: json azure-logic-apps