You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Logic App中将JSON字符串列表转为HTML表格用于邮件发送?

在Azure Logic Apps中将JSON数据转换为HTML表格并通过邮件发送

问题描述

我的Azure Logic App通过HTTP触发器接收如下JSON负载:

{
  "entry": [
    {
      "country": "USA",
      "person": "male",
      "visiting_time": "2023-08-14 12:00:00",
      "Name": "Kyle",
      "Surname": "Doe"
    },
    {
      "country": "Netherlands",
      "person": "female",
      "visiting_time": "2023-08-15 00:00:00",
      "Name": "Juliet",
      "Surname": "McMan"
    },
    ...
  ]
}

需要把这些数据转换成指定样式的HTML表格用于邮件发送,预期的HTML结构如下:

<div class="s-table-container">
  <table class="s-table">
    <thead>
      <tr>
        <th>Country</th>
        <th>Person</th>
        <th>visiting_time</th>
        <th>Name</th>
        <th>Surname</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>USA</td>
        <td>male</td>
        <td>2023-08-14 12:00:00</td>
        <td>Kyle</td>
        <td>Doe</td>
      </tr>
      <tr>
        <td>Netherlands</td>
        <td>female</td>
        <td>2023-08-15 00:00:00</td>
        <td>Juliet</td>
        <td>McMan</td>
      </tr>
      <tr>
        <td>...</td>
        <td>...</td>
        <td>...</td>
        <td>...</td>
        <td>...</td>
      </tr>
    </tbody>
  </table>
</div>

实现步骤

1. 提取entry数组

在HTTP触发器之后添加Compose动作,输入以下表达式提取JSON里的entry数组:

triggerBody()?['entry']

这一步把需要处理的数据源单独拎出来,方便后续操作。

2. 统一字段名(可选)

如果要把原JSON里的小写字段(比如country)转换成首字母大写的表头(比如Country),添加Select动作:

  • 输入内容选择上一步Compose的输出
  • 映射关系设置为:
    • Country: item()?['country']
    • Person: item()?['person']
    • visiting_time: item()?['visiting_time']
    • Name: item()?['Name']
    • Surname: item()?['Surname']
      不需要调整字段名的话,跳过这一步直接用原数组。

3. 生成基础HTML表格

添加Create HTML Table动作:

  • 输入内容选择Select的输出(或直接用Compose的entry数组)
  • 选择自定义模式,手动匹配表头和对应字段值(跳过Select步骤的话,直接映射原字段即可)

这一步会生成不带样式的纯HTML表格。

4. 套入指定样式结构

再添加一个Compose动作,把生成的表格内容嵌入到要求的样式容器里,输入以下内容:

<div class="s-table-container">
  <table class="s-table">
    <thead>
      <tr>
        <th>Country</th>
        <th>Person</th>
        <th>visiting_time</th>
        <th>Name</th>
        <th>Surname</th>
      </tr>
    </thead>
    <tbody>
      @replace(body('Create_HTML_Table'), '<table>', '').replace('</table>', '')
    </tbody>
  </table>
</div>

这里用表达式替换掉默认生成的<table>标签,把表格内容放到指定的结构中。

5. 发送HTML格式邮件

添加**Send an email (V2)**动作:

  • 邮件正文选择上一步Compose输出的带样式HTML内容
  • 确认邮件正文格式设置为HTML

这样就能发送符合要求的表格邮件了。

内容的提问来源于stack exchange,提问作者AzUser1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 00:06:26