Reputation: 303
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:
However the result I'm trying to achieve is merging the two id columns into one column like below:
Upvotes: 0
Views: 742
Reputation: 6104
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
}
]
}
]
}
flattenMain
and flattenSub
instead of 1 which use the same source.flattenMain
, I have unrolled by header
and selected unroll root as header
. Then created an additional column selecting source column header.main.id
.flattenMain
would be:flattenSub
, I have unrolled by header.sub
and selected unroll root as header.sub
. Then created 2 additional column selecting source column header.sub.id
as id column and header.sub.type
as type column.flattenSub
transformation would be:union
transformation on both flattenMain
and flattenSub
. I have applied union by
using Name.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.
Upvotes: 1