Azure 数据工厂 JSON 输出格式问题

问题描述 投票:0回答:1

我在 Azure 数据工厂中格式化 JSON 输出时遇到问题。我想要的 JSON 输出结构如下:

{
  "AccessionNum": "12345",
  "test": [
    {
      "orderunit": "JMJ",
      "Testname": "TVK"
    },
    {
      "orderunit": "PJ",
      "Testname": "CVK"
    }
  ]
}

但是,在 Azure 数据工厂中从 CSV 输入文件执行所有必要的操作后,生成的 JSON 输出如下,其中“test”数组元素被视为字符串而不是 JSON 对象:

{
  "AccessionNum": "12345",
  "test": [
    "{\"orderunit\":\"JMJ\",\"Testname\":\"TVK\"}",
    "{\"orderunit\":\"PJ\",\"Testname\":\"CVK\"}"
  ]
}

我已经在 Azure 数据工厂中尝试了各种表达式和转换,但无法实现所需的 JSON 结构,其中“测试”数组元素是正确的 JSON 对象。有人可以帮助我解决这个问题并在 Azure 数据工厂中实现正确的 JSON 输出格式吗?

提前感谢您的帮助!

在尝试解决 Azure 数据工厂中 JSON 输出的格式问题时,我在数据流管道中尝试了多种方法:

派生列转换:最初,我尝试使用 Azure 数据工厂中的“派生列”转换来创建具有适当 JSON 对象的“测试”数组。我使用了诸如

concat('{"orderunit":"',orderunit,'","Testname":"',testname,'"}')
生成数组。但是,这导致“测试”数组元素被视为字符串而不是 JSON 对象。

映射函数:我探索了 Azure 数据工厂表达式语言中的其他可用函数(例如 createMap、struct 和 array)来构造 JSON 对象。不幸的是,这些方法在 Azure 数据工厂中都不可用。

外部脚本: 作为解决方法,我考虑使用 Azure 数据工厂中的外部脚本或自定义活动来后处理数据并将其转换为正确的 JSON 格式。然而,我希望找到一个可以完全在 Azure 数据工厂管道中实现的解决方案。

就期望而言,我的目标是实现 JSON 输出格式,其中“测试”数组包含正确的 JSON 对象,如我最初的帖子所示:

{
  "AccessionNum": "12345",
  "test": [
    {
      "orderunit": "JMJ",
      "Testname": "TVK"
    },
    {
      "orderunit": "PJ",
      "Testname": "CVK"
    }
  ]
}

json azure azure-data-factory azure-logic-apps custom-data-type
1个回答
0
投票

Azure 数据工厂 JSON 输出格式问题

在您的情况下,您使用的是

concat
函数,它是字符串函数,因为它您正在获取字符串值。

要实现从 CSV 到 Json 的要求,您需要使用以下表达式

--In aggreagatea transformation
collect(@(orderunit=orderunit,      Testname=Testname))

--In derived column transformmation
array(@(orderunit=orderunit,        Testname=Testname))

我的示例输入数据集:

enter image description here

聚合变换:

enter image description here

enter image description here

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.