解析 Azure 数据工厂中的复杂 json 文件

Parse complex json file in Azure Data Factory

我想在 Azure 数据工厂中解析一个复杂的 json 文件。结构如下,这意味着有嵌套的对象和数组。根据我的理解,ADF 可以解析数组,但我们应该怎么做才能解析更复杂的文件?

文件结构如下

{
  "productA": {
         "subcategory 1" : [
             {
                "name":"x",
                "latest buy": "22-12-21"
                "total buys": 4
                "other comments": "xyzzy"
                "history data": [
                   {
                     "name":"x",
                     "latest buy": "22-12-21"
                     "total buys": 4
                     "other comments": {"John":"Very nice","Nick":"Not nice"}
                    }
                  ]
               }
            }
       }

您发布的 JSON 结构似乎有一些错误。这不是有效的 JSON 结构。它缺少逗号 (,) 和大括号。

当您拥有有效的 JSON 结构时,您可以在数据流中使用展平转换来展平 JSON。

来源:

{
 "productA": {
     "subcategory 1" : [
         {
            "name":"x",
            "latest buy": "22-12-21",
            "total buys": 4,
            "other comments": "xyzzy",
            "history data": [
               {
                 "name":"x",
                 "latest buy": "22-12-21",
                 "total buys": 4,
                 "other comments": {"John":"Very nice","Nick":"Not nice"}
                }
              ]
           }
           ]
        }
   }

ADF 数据流:

源转换:

将 JSON 数据集连接到源转换并在源选项中,在 JSON 设置下,select 单个文档。

源预览:

展平变换:

此处select您要在Unroll by和Unroll root中展开的数组级别并添加映射。

展平预览:

有关在 ADF 中解析 JSON 文档的更多详细信息,请参阅此 parse & flatten 文档。