我在Azure Data Factory中格式化JSON输出时遇到问题.我想要的JSON输出 struct 如下:

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

然而,在Azure Data Factory中从CSV输入文件执行所有必要的操作后,结果JSON输出如下所示,其中"测试"数组元素被视为字符串,而不是JSON对象:

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

我try 了Azure Data Factory中的各种表达式和转换,但我还没能实现所需的JSON struct ,其中的"测试"数组元素是合适的JSON对象.有人能帮助我解决这个问题并在Azure Data Factory中实现正确的JSON输出格式吗?

提前感谢您的帮助!

为了解决Azure Data Factory中JSON输出的格式化问题,我在数据流管道中try 了几种方法:

Derived Column Transformation:最初,我try 使用Azure数据工厂中的"派生列"转换来创建带有适当JSON对象的"测试"array.我使用了这样的表达方式 concat('{"orderunit":"',orderunit,'","Testname":"',testname,'"}')以生成array.然而,这导致"测试"数组元素被视为字符串,而不是JSON对象.

Mapping Functions:我探索了Azure Data Factory的表达式语言中的其他可用函数,如createMap、struct和数组,以构造JSON对象.不幸的是,这些方法在Azure数据工厂中都不可用.

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

就期望而言,我的目标是实现一种JSON输出格式,其中"test"数组包含适当的JSON对象,如我最初的帖子所示:

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

推荐答案

Azure Data Factory JSON输出格式问题

In your case you are using 100 function which is string function because of it you are getting string value.

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

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

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

My sample input dataset:

enter image description here

Aggregate transformation:

enter image description here

enter image description here

Output:

enter image description here

Json相关问答推荐

服务器不返回JSON

如何在JQ过滤器文件中使用多行?

Jolt-在数组列表中插入新的字段

Python 将 struct 化文本转换和筛选为对象

使用不同行数的数据创建嵌套Jolt

如何在JQ中展平多维数组

如何使用 SQL Server 将 json 存储为字符串的列分解/规范化为行和列?

我需要在 mongodb compass 中检索索引(编号 1)信息

在 PostgreSQL 中 Select 分层 JSON 作为表

如何在 wso2 中组合 2 个 json 有效负载?

Angular 2/Web Api - json 解析错误语法错误意外结束输入

现代浏览器一次可以处理多少个 HTML 元素?

Jackson 的@JsonView、@JsonFilter 和 Spring

在 JavaScript 中从 Json 数据中删除反斜杠

如何从Typescript 中的json响应中获取日期对象

使用 GSON 解析嵌套的 JSON 数据

我应该如何处理 JSON 中的 HATEOAS 链接和引用?

将 javascript 对象或数组转换为 json 以获取 ajax 数据

使用适用于 Python 的 Google API - 我从哪里获取 client_secrets.json 文件?

Microsoft.Net.Http 与 Microsoft.AspNet.WebApi.Client