02-13-2022 01:03 PM
What is the easiest way to convert a table to a nested JSON?
02-14-2022 02:12 AM
As Spark can handle nested columns, I would first construct the nested structure in spark (as from spark 3.1.1 there is the excellent column.withField method with which you can create your structure.
Finally write it to json.
That seems to be the easiest way, but your case might be more complex, that is hard to say without some more info.
02-13-2022 02:02 PM
@Sergio Paz could you please provide an example of your input table and expected output JSON file?
04-11-2022 07:52 PM
{
"accounts":[
"12516898"
],
"deals":[
{
"dealId":"4897143",
"promotionId":"AVC84897143",
"conditions":{
"paymentMethod":null,
"simulationDateTime":{
"startDateTime":"2022-03-16",
"endDateTime":"2022-04-30"
},
"scaledLineItem":{
"sharedMinimumQuantity":true,
"skus":[
"000000000000000031"
],
"crossDiscount":true,
"ranges":[
{
"index":"1",
"from":1,
"to":200
}
]
}
},
"output":{
"lineItemScaledDiscount":{
"ranges":[
{
"index":"1",
"skus":[
"000000000000000031"
],
"type":"%",
"discount":5.5,
"maxQuantity":null,
"proportion":null,
"fixed":true
}
]
}
}
}
]
}
02-14-2022 02:12 AM
As Spark can handle nested columns, I would first construct the nested structure in spark (as from spark 3.1.1 there is the excellent column.withField method with which you can create your structure.
Finally write it to json.
That seems to be the easiest way, but your case might be more complex, that is hard to say without some more info.
03-06-2022 04:08 PM
@Sergio Paz - How's it going? Are you able to give us more information?
03-22-2022 02:22 PM
Hi @Sergio Paz ,
Just a friendly follow-up. Could you provide more details on your use case? please share your code snippet, so we can help you.
Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections.
Click here to register and join today!
Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.