首页 > 解决方案 > 在逻辑应用程序中将数组拆分为包含两个数组的 JSON

问题描述

我有这个 JSON:

[
  {
    "ParentReasonId": 2,
    "ParentReason": "Violent or repulsive content",
    "ReasonId": 15,
    "Reason": "Adults fighting"
  }, 
  {
    "ParentReasonId": 2,
    "ParentReason": "Violent or repulsive content",
    "ReasonId": 16,
    "Reason": "Physical attack"
  }
]

使用天蓝色逻辑应用程序,我正在尝试将数组转换为两个数组的 json:

{
    "categories": [
         {
        "categoryId": 2,
        "category": "Violent or repulsive content"
     }
        ],
    "reasons": [
     {
                "categoryId": 2,
        "reasonId": 15,
        "reason": "Adults fighting"
     },
     {
                "categoryId": 2,
        "reasonId": 16,
        "reason": "Physical attack"
     }
    ]
}

我如何使用 azure 逻辑应用程序来实现这一点?数据来自 sql 存储过程操作。

标签: arrayssql-serverazurestored-proceduresazure-logic-apps

解决方案


从 SQL Server 获取数据后,您可以执行以下操作之一

  1. 使用 Azure Functions
    您可以简单地拥有一个 azure 函数,该函数执行您需要的转换,并且将从您的逻辑应用程序中调用该函数。

    有关如何实现此目的的更多信息,请参阅使用 Azure Functions 的自定义代码文档。

    这可能是最简单且更具成本效益的解决方案。

  2. 使用集成帐户和流动模板
    如果您想避免编写和维护代码,您可以采用这种方法,包括为您的转换编写流动模板,将其上传到集成帐户并从您的逻辑应用程序中调用它。

    有关如何实现此目的的更多信息,请参阅Transform JSON文档。

    尽管这种方法避免了维护代码,但请注意集成帐户会产生每小时费用。如果您有很多这样的转换,那么使用它可能是有意义的。

此外,您可以尝试使用逻辑应用提供的内置连接器工作流定义语言功能来实现相同的功能,但可能有点过于复杂。


推荐阅读