- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ02-13-2022 01:03 PM
What is the easiest way to convert a table to a nested JSON?
- Labels:
-
Complex Json File
-
Convert
-
Table
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ02-13-2022 02:02 PM
@Sergio Pazโ could you please provide an example of your input table and expected output JSON file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ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
}
]
}
}
}
]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ03-06-2022 04:08 PM
@Sergio Pazโ - How's it going? Are you able to give us more information?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
โ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.

