How to flatten array parameter into a file

Priya Jha 901 Reputation points
2022-10-13T13:00:23.39+00:00

Hi All,

I have a pipeline parameter which is a nested array as below:

[[1,2,3],[2,3,4],[3,4,5]]

I want to copy this array into a csv file in below format,

1,2,3
2,3,4
3,4,5

@AnnuKumari-MSFT @Nandan Hegde

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
{count} votes

1 answer

Sort by: Most helpful
  1. KranthiPakala-MSFT 46,737 Reputation points Microsoft Employee Moderator
    2022-10-14T23:24:44.367+00:00

    Hello @Priya Jha ,

    Thanks for the question and using MS Q&A platform.

    I was working on a similar requirement where my source was like below(similar to yours):

    [  
    	{  
    		"name": "jsonData",  
    		"value": "[[1,22,\"AAAA\"],[888,999,\"AXAXAXAX\"]]"  
    	}  
    ]  
    

    Which I would like to transform to below output format in CSV/txt:

    250676-image.png

    Below are the transformations I have followed to achieve it.

    250637-image.png

    First use a derived column transformation to unfold the nested arrays using the below expression.

    unfold(split(dropRight(dropLeft(value, 2),2),'],['))

    250666-image.png

    The data preview of dataflow will look like below:

    250644-image.png

    Then use a parse transformation to parse the coma separated string values and split them to individual column as shown below:

    250721-image.png

    The data preview would look like below. (Note: Looks like there is a visual/UI bug in while previwing the data for parse transofrmation, I'll work with product team to fix this issue, but this is not a blocker as it is visual issue)

    250657-image.png

    Then lastly have a select transformation and select the columns that you would like to copy to your sink. In my example, I will have to select columns a , b, c .

    250627-image.png

    Lastly have a sink transformation and write to your desired sink.

    250722-image.png

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.