根据 POST 请求的输出在 JSON 对象中创建一个数组

Create an array from the output of POST request in JSON Object

我正在尝试通过 Logic App 发送电子邮件。 内容必须是孤立资源的数组。

我正在使用 HTTP 请求查询 Azure 资源图资源管理器,在输出中我有一个 JSON 对象。我想在数组上转换这个 JSON 对象。

如何从 HTTP POST 请求的输出中获取数组?

如果该结构已知,您可以在 parse JSON 操作中使用特定模式将其解析为(一组)对象。

To reference or access properties in JavaScript Object Notation (JSON) content, you can create user-friendly fields or tokens for those properties by using the Parse JSON action. That way, you can select those properties from the dynamic content list when you specify inputs for your logic app. For this action, you can either provide a JSON schema or generate a JSON schema from your sample JSON content or payload.

文章 Perform data operations in Azure Logic Apps 显示了您正在尝试实现的确切示例,查看您的屏幕截图。

以下是它对我有用的方法:

考虑提供的 JSON 而不是在 Create HTML table 中使用 body 作为 From 数据 我使用 data 自 Create HTML table 仅将数组作为输入,然后在发送电子邮件时对其进行修改。

这是我的逻辑应用程序:

这是电子邮件:

更新答案

这是整个逻辑应用程序

为了解析 JSON,我正在使用示例负载生成架构,该负载具有与您提供的示例值相同的 JSON。即..

{
  "body": {
    "totalRecords": 25,
    "count": 25,
    "data": [
      {
        "id": "SampleId",
        "diskState": "Sample",
        "resourceGroup": "dkfdfjsi",
        "location": "gareg",
        "subscriptionId": "fgser"
      },
      {
        "id": "SampleID2",
        "diskState": "SAmple2",
        "resourceGroup": "dkfdfjsi",
        "location": "gareg",
        "subscriptionId": "fgser"
      }
    ]
  }
}

由于您的要求是以表格格式发送数据,我使用了与您相同的连接器,即 Create HTML Tabledata 数组作为连接器的输入,因此它将生成table 自动与 headers 格式如下

最后,我使用 HTML Table 连接器的输出来发送电子邮件

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

{
   "definition": {
       "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
       "actions": {
           "Create_HTML_table_2": {
               "inputs": {
                   "format": "HTML",
                   "from": "@body('Parse_JSON')?['body']?['data']"
               },
               "runAfter": {
                   "Parse_JSON": [
                       "Succeeded"
                   ]
               },
               "type": "Table"
           },
           "Parse_JSON": {
               "inputs": {
                   "content": "@triggerBody()",
                   "schema": {
                       "properties": {
                           "body": {
                               "properties": {
                                   "count": {
                                       "type": "integer"
                                   },
                                   "data": {
                                       "items": {
                                           "properties": {
                                               "diskState": {
                                                   "type": "string"
                                               },
                                               "id": {
                                                   "type": "string"
                                               },
                                               "location": {
                                                   "type": "string"
                                               },
                                               "resourceGroup": {
                                                   "type": "string"
                                               },
                                               "subscriptionId": {
                                                   "type": "string"
                                               }
                                           },
                                           "required": [
                                               "id",
                                               "diskState",
                                               "resourceGroup",
                                               "location",
                                               "subscriptionId"
                                           ],
                                           "type": "object"
                                       },
                                       "type": "array"
                                   },
                                   "totalRecords": {
                                       "type": "integer"
                                   }
                               },
                               "type": "object"
                           }
                       },
                       "type": "object"
                   }
               },
               "runAfter": {},
               "type": "ParseJson"
           },
           "Send_an_email_(V2)_2": {
               "inputs": {
                   "body": {
                       "Body": "<p><strong>Total Records</strong> :@{body('Parse_JSON')?['body']?['totalRecords']} , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Count </strong>: @{body('Parse_JSON')?['body']?['count']}<br>\n-----------------------------------------------------------------------------<br>\n@{body('Create_HTML_table_2')}</p>",
                       "Subject": "Sample Test",
                       "To": "<YOUR REQUIRED EMAIL ID>"
                   },
                   "host": {
                       "connection": {
                           "name": "@parameters('$connections')['office365']['connectionId']"
                       }
                   },
                   "method": "post",
                   "path": "/v2/Mail"
               },
               "runAfter": {
                   "Create_HTML_table_2": [
                       "Succeeded"
                   ]
               },
               "type": "ApiConnection"
           }
       },
       "contentVersion": "1.0.0.0",
       "outputs": {},
       "parameters": {
           "$connections": {
               "defaultValue": {},
               "type": "Object"
           }
       },
       "triggers": {
           "manual": {
               "inputs": {},
               "kind": "Http",
               "type": "Request"
           }
       }
   },
   "parameters": {
       "$connections": {
           "value": {
               "office365": {
                   "connectionId": "/subscriptions/<YOUR SUBSCRIPTION ID>/resourceGroups/<YOUR RESOURCE GROUP>/providers/Microsoft.Web/connections/office365",
                   "connectionName": "office365",
                   "id": "/subscriptions/<YOUR SUBSCRIPTION ID>/providers/Microsoft.Web/locations/northcentralus/managedApis/office365"
               }
           }
       }
   }
}

@SwethaKandikonda-MT

我使用递归作为触发器。在我使用 http 连接器查询 Azure 资源图以获得 kql 请求的结果之后。 在 http 之后我得到了 json 对象。我和你一样使用具有相同模式的 Parse Json。我在 html table 之后创建了来自解析 Json 的数据,但是当我 运行 loguc 应用程序时,它会出错,因为 html table 被认为是 null