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

如何在Power Automate中转换API返回的嵌套对象为可用数组

解决方案:将键值对对象转换为数组(适配Power Automate操作)

方案一:Power Automate原生功能实现(无代码)

  • 第一步:解析API响应
    添加「解析JSON」操作,将API返回的原始响应作为输入,使用以下Schema自动生成(或手动编写):
    {
      "type": "object",
      "properties": {
        "987654321": {
          "type": "object",
          "properties": {
            "title": {"type": "string"},
            "amount": {"type": ["integer", "null"]},
            "id": {"type": "string"}
          }
        },
        "876543210": {
          "type": "object",
          "properties": {
            "title": {"type": "string"},
            "amount": {"type": ["integer", "null"]},
            "id": {"type": "string"}
          }
        }
      }
    }
    
  • 第二步:提取对象值为数组
    添加「Compose」操作,输入表达式:
    values(body('解析JSON'))
    
  • 第三步:直接使用转换结果
    Compose操作的输出就是标准数组,可直接接入「Select」或「Apply to Each」操作。

方案二:Office Scripts实现(适合复杂扩展)

如果原生功能需要扩展,可通过脚本处理:

  1. 在Power Automate中添加「Run script」操作,关联任意Excel文件(仅作为脚本运行载体)
  2. 编写以下TypeScript脚本:
    function main(workbook: ExcelScript.Workbook, inputObj: object) {
      // 提取对象所有值并转为数组
      return Object.values(inputObj);
    }
    
  3. 将API返回的原始对象作为脚本输入参数,输出结果即为目标数组。

核心原理

values()是Power Automate和JavaScript的原生方法,专门用于提取对象的所有属性值并返回数组,完全匹配你的格式转换需求,转换后的结构天然支持Power Automate的批量操作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.01 13:19:56