简体   繁体   English

如何直接在 Azure 数据工厂管道中转换 JSON 数据

[英]How to transform a JSON data directly in a Azure Data Factory pipeline

I have a lookup in a Azure Data Factory pipeline which is connected to a data flow.我在连接到数据流的 Azure 数据工厂管道中进行了查找。 The lookup returns a JSON array in the form:查找以以下形式返回一个 JSON 数组:

[
    {
        "COLUMN_NAME": "country_code"
    },
    {
        "COLUMN_NAME": "customer_role"
    },
    {
        "COLUMN_NAME": "valid_from"
    },
    {
        "COLUMN_NAME": "valid_to"
    }
]

The data flow accepts an array of strings as parameter.数据流接受一个字符串数组作为参数。 Therefore I need a way to transform the data from the lookup to an array of strings in the form:因此,我需要一种方法将数据从查找转换为以下形式的字符串数组:

[
    "country_code",
    "customer_role",
    "valid_from",
    "valid_to"
]

In my pipeline the output from the lookup is available as pipeline expression: @activity('GetKeyColumns').output.value .在我的管道中,查找的输出可用作管道表达式: @activity('GetKeyColumns').output.value

For the data flow I can choose if I will use data flow expression or a pipeline expression to pass the parameter (array of strings).对于数据流,我可以选择是使用数据流表达式还是管道表达式来传递参数(字符串数组)。 The data flow expression has a map function which is able to map the data structure.数据流表达式有一个能够映射数据结构的映射函数。 But I have no idea how I can use the output from the lookup in this function.但我不知道如何使用此函数中查找的输出。

Is there a way how I can achieve this transformation in my pipeline?有没有办法在我的管道中实现这种转变?

You can add a variable, type is array, then use For Each activity and append variable activity.您可以添加一个变量,类型为数组,然后使用 For Each 活动并附加变量活动。

Step:步:

1.create a variable named string_array 1.创建一个名为string_array的变量在此处输入图片说明

2.create a For Each activity,expression: @activity('GetKeyColumns').output.value 2.创建一个 For Each 活动,表达式: @activity('GetKeyColumns').output.value 在此处输入图片说明

3.create a Append variable activity inside For each avtivity,expression: @item()['COLUMN_NAME'] 3.在里面创建一个Append变量activity For each avtivity,expression: @item()['COLUMN_NAME'] 在此处输入图片说明

4.pass string_array to data flow by using pipeline expression: @variables('string_array') 4.通过使用管道表达式将string_array传递给数据流: @variables('string_array') 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM