【问题标题】:Is there a way to read nested array and extract only one value from the nested array using Azure Data Factory?有没有办法使用 Azure 数据工厂读取嵌套数组并从嵌套数组中仅提取一个值?
【发布时间】:2021-04-29 10:27:35
【问题描述】:

我需要从我的存储帐户中读取 json 文件,并仅从 json 对象数组中获取 id,并仅从数组中提取 id。

我尝试使用查找活动来获取 json 对象数组,并通过提供 @array(activity('Lookup').output.value[0].lists) 将该输出用于每个活动。

下面的json脚本是查找活动的输出

"count": 1,
    "value": [
        {
            "obj": 123,
            "lists": {
                "employees": [
                    {
                        "name": "",
                        "id": "001",
                        "tt_1": 0,
                        "tt_2": 4,
                        "tt3_": 1
},
{
                        "name": "",
                        "id": "002",
                        "tt_1": 10,
                        "tt_2": 8,
                        "tt3_": 1
}```

Need some way to loop through the array of objects and extract only the id and save it in a separate file.
I tried to narrow down till employees using set variables array type but unable to loop through array of objects and extract the id 

Please help me to find out some solution to extract the id from the array? Please suggest if sqldb or any other way to extract id?

【问题讨论】:

  • 嗨@dfbeg,如果我的回答对您有帮助,请接受它作为答案(单击答案旁边的复选标记将其从灰色切换为已填充。)。这对其他社区成员可能是有益的。谢谢。

标签: json azure azure-data-factory-2


【解决方案1】:

您可以使用数据流Flatten active将json数组value.list.employees展平得到ID值,然后将id导入csv文件。

我只是和你创建了一个相同的 JSON 数据,请参考下面的示例。

{   
    "count": 1,
    "value": [{
                "obj": 123,
                "lists": [{
                            "employees": [{
                                
                                    "name": "",
                                    "id": "001",
                                    "tt_1": 0,
                                    "tt_2": 4,
                                    "tt3_": 1
                                },
                                {
                                    "name": "",
                                    "id": "002",
                                    "tt_1": 10,
                                    "tt_2": 8,
                                    "tt3_": 1
                                }]
                        }]
                }]                  
}

源数据和架构:

展平活动设置和输出预览:

然后我们可以将 ID 数据复制到 SQL DB 或 csv 文件。

HTH。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多