jsonazure-data-factoryazure-mapping-data-flow

ADF Data Flow flatten JSON to rows


IN ADF Data Flow how can I flatten JSON into rows rather than columns?

{                   
                "header": [
                    {                           
                        "main": {                                
                            "id": 1                               
                        },
                        "sub": [
                            {
                                "type": "a",                                   
                                "id": 2                                  
                            },
                            {
                                "type": "b",                                   
                                "id": 3                                 
                            }
                              
                              ]}]}

In ADF I'm using the flatten task and get the below result:

enter image description here

However the result I'm trying to achieve is merging the two id columns into one column like below:

enter image description here


Solution

  • Since both main_id and sub_id belong in the same column, instead of using 1 flatten to flatten all the data, flatten both main and sub separately.

    {
       "header":[
          {
             "main":{
                "id":1
             },
             "sub":[
                {
                   "type":"a",
                   "id":2
                },
                {
                   "type":"b",
                   "id":3
                }
             ]
          },
          {
             "main":{
                "id":4
             },
             "sub":[
                {
                   "type":"c",
                   "id":5
                },
                {
                   "type":"d",
                   "id":6
                }
             ]
          }
       ]
    }
    

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    NOTE: All the highlighted rows in output images indicate the result that would be achieved when we use the JSON sample provided in the question.