Split a json string column or flatten transformation in data flow (ADF)

那年仲夏 提交于 2021-02-11 14:36:31

问题


I copy the following csv file to a data flow in ADF.

The column Data has json format, but it is considered string. I want to flatten Data column into individual rows. I tried the flatten transformation, it did not work as Data column is not json. How do I deal with it? I also tried split expression, and it did not work either. Thank you


回答1:


Just from your screenshot, We can find that :

  1. The data in Data are not JSON format.
  2. Data most look like an Array.
  3. The 'array' has 9 elements.

Me must consider it as the "Array" then we could using Data Flow Derived Column to flatten the Data. Please ref my steps bellow:

Source data:

Derived Column expressions and settings:

The expression to make data as string and using index to get the value:

Data 1: split(substring(Data, 2, length(Data)-2), ",")[1]
Data 2: split(substring(Data, 2, length(Data)-2), ",")[2]
Data 3: split(substring(Data, 2, length(Data)-2), ",")[3]
Data 4: split(substring(Data, 2, length(Data)-2), ",")[4]
Data 5: split(substring(Data, 2, length(Data)-2), ",")[5]
Data 6: split(substring(Data, 2, length(Data)-2), ",")[6]
Data 7: split(substring(Data, 2, length(Data)-2), ",")[7]
Data 8: split(substring(Data, 2, length(Data)-2), ",")[8]
Data 9: split(substring(Data, 2, length(Data)-2), ",")[9]

Derived Column output:

If the Data are standard JSON format, we need convert the string to JSON first, and then use the key to get the value.

HTH.



来源:https://stackoverflow.com/questions/65741675/split-a-json-string-column-or-flatten-transformation-in-data-flow-adf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!