Home > front end >  Convert JSON to CSV in Azure Data Factory
Convert JSON to CSV in Azure Data Factory

Time:01-17

I have a problem with converting JSON to CSV. JSON looks like that:

{
  "Key1": "Value1",
  "Key2": "Value3",
  "Key3": "Value2",
  ...
}

And I expect the CSV in this format:

Key, Value
Key1, Value1
Key2, Value2
Key3, Value3
...

As you see keys and values are stored in column. Is it possible to do that in data flow in Azure Data Factory?

CodePudding user response:

You can make use of flatten transformation in data flow. Please check the below Microsoft documentation page.

enter image description here

Data flow:

  1. Add Source and connect it to the JSON Input file. In source options under JSON settings, select the document form as Single document.

enter image description here

Source Data preview:

enter image description here

  1. Add derived column after source to add a dummy column with a constant value to later use it in Unpivot transformation.

enter image description here

Derived column Data preview:

enter image description here

  1. Add Unpivot transformation after Derived column, to convert columns to rows. Under Unpivot settings

    a) Ungroup by: Select dummy column.

    b) Unpivot key: Give a name to an unpivot column (Ex: Key), type as ‘string’.

    c) Unpivoted columns: Give a column name for the data in unpivoted columns.

enter image description here

enter image description here

enter image description here

Unpivot Data preview:

enter image description here

  1. Add Select transformation after Unpivot to remove the dummy column and select only required columns to the output.

enter image description here

Select Data preview:

enter image description here

  1. Add sink transformation at the end and connect to sink delimited dataset. In Settings, if you select the File name option as Output to single file, you can provide the sink file name.

enter image description here

Sink Data preview:

enter image description here

Output:

enter image description here

  •  Tags:  
  • Related