Logic Apps工作流程中的JSON对象属性设置

时间:2018-03-13 10:06:47

标签: json azure-logic-apps

基本上,我正在创建一个复杂的JSON Object变量,实际上是其中两个。一个用于构成对响应应用程序的HTTP响应的主体,另一个用于形成POST的主体到API。复杂的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"
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

  

一个用于形成对响应应用程序的HTTP响应的主体,另一个用于形成POST的主体到API ....我有很多属性设置要做。

然后你应该使用转换而不是Compose。

由于内容已经是JSON,因此最直接的路径是Liquid Transform

但是,如果您已经熟悉Xsl,那么这也是一个选项。