Json object transform

Pratisti Satardekar 90 Reputation points
2024-03-13T18:24:06.35+00:00

hi,

I wanted to form a json object in a derived Column as following:
"categories": [

{

  "id": 9

},

{

  "id": 14

}

]

the id's are stored in diff columns.
ex: User's image

Can you please guide me

Thanks,

Pratisti Satardekar

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,548 questions
{count} votes

1 answer

Sort by: Most helpful
  1. AnnuKumari-MSFT 30,751 Reputation points Microsoft Employee
    2024-03-14T08:31:05.0666667+00:00

    Hi Pratisti Satardekar ,

    Thankyou for using Microsoft Q&A platform and thanks for posting your query here.

    As per my understanding you are trying to perform data transformation and convert tabular data into json using mapping dataflow . The challenge here is id1,id2 columns needs to be converted as single key in json named as 'id'. Please let me know if that is not the correct understanding.

    This can't be directly achieved using derived column transformation. Since the column names needs to be coming as same 'id' , we need to perform unpivot first so that both the values 4, and 9 comes under same column and that can be used in derived column transformation to convert as key of json.

    • First of all , add source transformation to point to the source file.
    • Now, add 'surrogate key transformation' to create a new column ,say 'key' that will generate unique value corresponding to each records. This column will be used to ungroup by in 'unpivot transformation'

    User's image

    • Use 'Unpivot transformation' to modify data from being placed in two columns to single column. To ungroup by , we will use 'key' column. In unpivot key tab, provide the new col name as 'unpivotedcol'. In unpivoted columns tab, select 'id1' and 'id2' as the column names
      User's image
    • Now use derived column transformation and provide column name as 'collections' and in expression , add new subcolumn and provide the expression as @(id=id1)
      User's image
    • Add an aggregate transformation to convert complex column 'collections' as an array with the help of collect function. Leave the group by tab as blank and go to aggregates tab, select 'collections' column and provide expression as collect(collections)
      User's image
    • Now, add sink transformation to store the output json data. In settings , select filename option as 'output to single file' and set single partition , provide output filename and run the dataflow. User's image Hope it helps. Kindly accept the answer by clicking on Accept answer button. Thankyou
    0 comments No comments