首页 > 解决方案 > 拆分 JSON 输入并在 Alteryx 工作流中应用与列名相同的 JSON 字段名称

问题描述

我正在使用 Alteryx 2019.3 并希望构建一个使用 JSON 作为输入的工作流。当它读取 JSON 时,它会将 JSON 键值对放入名为 JSON_Name 和 JSON_ValueString 的列中

在我模拟的示例中,下面 JSON 中的字段名称在 JSON_Name 列中如下所示:

customer.0.name
customer.0.contactDetails.0.company
customer.0.contactDetails.0.addressDetails.0.address
customer.0.contactDetails.0.addressDetails.0.addressType
customer.0.departments.0.name

我想要做的是把它分成不同的表,并将 JSON_Name 值的最后一部分作为列名,所以它看起来像这样(大写显示表名):

CUSTOMER
customerId

CONTACTDETAILS
customerId
company

ADDRESSDETAILS
customerId
address
addressType

DEPARTMENTS
customerId
name

我如何在 Alteryx 中执行此操作,以及当我在 JSON 列表中可以有多个条目时如何让它工作?

谢谢你的帮助

JSON 输入(例如模拟)

{
    "id": "1234",
    "contactDetails": [{
        "company": "company1",
        "addressDetails": 
        [{
            "address": "City1",
            "addressType": "Business"
        }]
    }]
    "departments": 
    [{
        "name": "dept1
    }]
}

标签: alteryx

解决方案


您可以使用 Text to columns 执行此操作,然后使用一系列过滤器将其拆分为不同的数据集(表)。您可能希望使用交叉表来获得正确的表格格式。


推荐阅读