将参数插入逻辑应用中的 JSON 数组

发布于 2025-01-10 19:10:37 字数 1847 浏览 5 评论 0 原文

我正在创建一个逻辑应用程序,使用 API 调用从一个平台收集成员,并使用 POST 方法将它们发布到另一个平台。在整个过程结束时,我得到一个包含我需要的数据的 JSON 数组。但是,我需要在开头添加一个参数到数组中。我该怎么做呢?

目前,我的数组如下所示

[
  {
    "company": "",
    "email": "",
    "firstName": "",
    "lastName": "",
    "nickname": "",
    "prefix": "",
    "sourceId": "",
    "title": "",
    "workPhone": ""
  },
  {
    "company": "",
    "email": "",
    "firstName": "",
    "lastName": "",
    "nickname": "",
    "prefix": "",
    "sourceId": "",
    "title": "",
    "workPhone": ""
  }
]

,我需要 HTTP 请求的正文如下所示:

**{"data":**
    [
     **"dataRecord":** {
        "company": "",
        "email": "",
        "firstName": "",
        "lastName": "",
        "nickname": "",
        "prefix": "",
        "sourceId": "",
        "title": "",
        "workPhone": ""
      },
      {
        "company": "",
        "email": "",
        "firstName": "",
        "lastName": "",
        "nickname": "",
        "prefix": "",
        "sourceId": "",
        "title": "",
        "workPhone": ""
      }
    }

我当前的流程如下所示:

  • Scheduled Trigger

  • 列表项

  • 验证平台(至)

  • 验证平台(来自)

  • 获取数据

  • 编写数据

  • 解析Json

  • 初始化数组变量

  • 为每个

    : (1)Compose - 将解析的 JSON 数据映射到目标字段 (2)追加到数组变量

  • 组成表达式:string(variables('variable'))

  • 将字符串撰写为 Json:json(string(outputs('Compose_2')))

  • HTTP POST

编辑: 添加我需要在输出中显示数据的位置的屏幕截图,以及我的应用程序的外观

每个之后的 JSON 输出

应用布局

I am creating a Logic app to gather members from one platform using an API call and posting them to another platform using POST method. At the end of the entire process, I get a JSON array with the data that I need. However, I need to add in a parameters into the array at the beginning. How would I go about doing so?

Currently, my array looks like this

[
  {
    "company": "",
    "email": "",
    "firstName": "",
    "lastName": "",
    "nickname": "",
    "prefix": "",
    "sourceId": "",
    "title": "",
    "workPhone": ""
  },
  {
    "company": "",
    "email": "",
    "firstName": "",
    "lastName": "",
    "nickname": "",
    "prefix": "",
    "sourceId": "",
    "title": "",
    "workPhone": ""
  }
]

I need for the body of my HTTP request to look like this:

**{"data":**
    [
     **"dataRecord":** {
        "company": "",
        "email": "",
        "firstName": "",
        "lastName": "",
        "nickname": "",
        "prefix": "",
        "sourceId": "",
        "title": "",
        "workPhone": ""
      },
      {
        "company": "",
        "email": "",
        "firstName": "",
        "lastName": "",
        "nickname": "",
        "prefix": "",
        "sourceId": "",
        "title": "",
        "workPhone": ""
      }
    }

My current flow looks like this:

  • Scheduled Trigger

  • List item

  • Authenticate platform (to)

  • Authentication platform(from)

  • Get Data

  • Compose data

  • Parse Json

  • Initialize Array Variable

  • For Each:
    (1)Compose - Map Parsed JSON data to Destination Fields
    (2)Append to array variable

  • compose expression: string(variables('variable'))

  • Compose string to Json: json(string(outputs('Compose_2')))

  • HTTP POST

Edit:
Adding screenshot of where I need the data to be in the output, along with what my app looks like

JSON Output after for each

App layout

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个少女永远怀春 2025-01-17 19:10:37

收到 json 数组后,尝试使用数据操作连接器的 Parse Json 操作来获取参数,然后可以使用 Compose 连接器形成 json。这是我的逻辑应用程序的屏幕截图,供您参考。

输入图片此处描述

这是输出:

在此处输入图像描述

在此处输入图像描述

这是撰写连接器中的架构

{
  "data": [
    {
      "dataRecord": {
        "company": "@{items('For_each')['company']}",
        "email": "@{items('For_each')['email']}",
        "firstName": "@{items('For_each')['firstName']}",
        "lastName": "@{items('For_each')['lastName']}",
        "nickname": "@{items('For_each')['nickname']}",
        "prefix": "@{items('For_each')['prefix']}",
        "sourceId": "@{items('For_each')['sourceId']}",
        "title": "@{items('For_each')['title']}",
        "workPhone": "@{items('For_each')['workPhone']}"
      }
    }
  ]
}

下面是代码我的逻辑应用程序的视图

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Compose": {
                        "inputs": {
                            "data": [
                                {
                                    "dataRecord": {
                                        "company": "@{items('For_each')['company']}",
                                        "email": "@{items('For_each')['email']}",
                                        "firstName": "@{items('For_each')['firstName']}",
                                        "lastName": "@{items('For_each')['lastName']}",
                                        "nickname": "@{items('For_each')['nickname']}",
                                        "prefix": "@{items('For_each')['prefix']}",
                                        "sourceId": "@{items('For_each')['sourceId']}",
                                        "title": "@{items('For_each')['title']}",
                                        "workPhone": "@{items('For_each')['workPhone']}"
                                    }
                                }
                            ]
                        },
                        "runAfter": {},
                        "type": "Compose"
                    }
                },
                "foreach": "@body('Parse_JSON')",
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@triggerBody()",
                    "schema": {
                        "items": {
                            "properties": {
                                "company": {
                                    "type": "string"
                                },
                                "email": {
                                    "type": "string"
                                },
                                "firstName": {
                                    "type": "string"
                                },
                                "lastName": {
                                    "type": "string"
                                },
                                "nickname": {
                                    "type": "string"
                                },
                                "prefix": {
                                    "type": "string"
                                },
                                "sourceId": {
                                    "type": "string"
                                },
                                "title": {
                                    "type": "string"
                                },
                                "workPhone": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "company",
                                "email",
                                "firstName",
                                "lastName",
                                "nickname",
                                "prefix",
                                "sourceId",
                                "title",
                                "workPhone"
                            ],
                            "type": "object"
                        },
                        "type": "array"
                    }
                },
                "runAfter": {},
                "type": "ParseJson"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

After receiving the json array try using Parse Json action of Data Operations Connector to get the parameters and then you can form a json using Compose Connector. Here is the screenshot of my logic app for your reference.

enter image description here

Here is the output:

enter image description here

enter image description here

Here is the schema in the compose connector

{
  "data": [
    {
      "dataRecord": {
        "company": "@{items('For_each')['company']}",
        "email": "@{items('For_each')['email']}",
        "firstName": "@{items('For_each')['firstName']}",
        "lastName": "@{items('For_each')['lastName']}",
        "nickname": "@{items('For_each')['nickname']}",
        "prefix": "@{items('For_each')['prefix']}",
        "sourceId": "@{items('For_each')['sourceId']}",
        "title": "@{items('For_each')['title']}",
        "workPhone": "@{items('For_each')['workPhone']}"
      }
    }
  ]
}

Below is the code view of my logic app

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Compose": {
                        "inputs": {
                            "data": [
                                {
                                    "dataRecord": {
                                        "company": "@{items('For_each')['company']}",
                                        "email": "@{items('For_each')['email']}",
                                        "firstName": "@{items('For_each')['firstName']}",
                                        "lastName": "@{items('For_each')['lastName']}",
                                        "nickname": "@{items('For_each')['nickname']}",
                                        "prefix": "@{items('For_each')['prefix']}",
                                        "sourceId": "@{items('For_each')['sourceId']}",
                                        "title": "@{items('For_each')['title']}",
                                        "workPhone": "@{items('For_each')['workPhone']}"
                                    }
                                }
                            ]
                        },
                        "runAfter": {},
                        "type": "Compose"
                    }
                },
                "foreach": "@body('Parse_JSON')",
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@triggerBody()",
                    "schema": {
                        "items": {
                            "properties": {
                                "company": {
                                    "type": "string"
                                },
                                "email": {
                                    "type": "string"
                                },
                                "firstName": {
                                    "type": "string"
                                },
                                "lastName": {
                                    "type": "string"
                                },
                                "nickname": {
                                    "type": "string"
                                },
                                "prefix": {
                                    "type": "string"
                                },
                                "sourceId": {
                                    "type": "string"
                                },
                                "title": {
                                    "type": "string"
                                },
                                "workPhone": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "company",
                                "email",
                                "firstName",
                                "lastName",
                                "nickname",
                                "prefix",
                                "sourceId",
                                "title",
                                "workPhone"
                            ],
                            "type": "object"
                        },
                        "type": "array"
                    }
                },
                "runAfter": {},
                "type": "ParseJson"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文