I have data.csv as follows using which i intend to create json for d3js sun burst visualization:
REGION_CODE,LOCATION_CODE,SKU_CODE,BASIC_SALES
Region 0,Location 10,SKU 500118,25
Region 0,Location 10,SKU 500122,34
Region 0,Location 11,SKU 500123,34
Region 0,Location 11,SKU 500124,68
I'm trying to convert it into a nested json as follows :
{
'name': 'region 0',
'shortName': 'region 0',
'children': [
{
'name': 'location 10',
'shortName': 'location 10',
'children':[
{
'name': 'SKU 500118',
'shortName': 'SKU 500118',
'size': '25'
},
{
'name': 'SKU 500122',
'shortName': 'SKU 500122',
'size': '34'
}
]
},
{
'name': 'location 11',
'shortName': 'location 11',
'children': [
{
'name': 'SKU 500123',
'shortName': 'SKU 500123',
'size': '34'
},
{
'name': 'SKU 500124',
'shortName': 'SKU 500124',
'size': '68'
}
]
}
]
}
I found an almost similar solution on Stackoverflow, convert-csv-to-json-tree-structure but it does down till the last row and adds it as children, while i want the the second last row to be added as children and the last row to be added as size as shown above.