I have CSV file (data.csv
) which contains a column with its parent id. Based on this file, I would like to create one or many json
files which contain the root and all its children. An example for a CSV file with one root only:
BrandID,Name,ParentBrandID
1,Brand,
2,Normal Brand,1
3,Bad Brand,1
4,Best Brand,1
5,Cleaner,4
6,Fat Remover,4
7,Others,1
8,Kitchen,7
And I need to convert that file to a json
format that looks like this:
{
"name":"Brand",
"children":[
{
"name":"Normal Brand"
},
{
"name":"Bad Brand"
},
{
"name":"Best Brand",
"children":[
{
"name":"Cleaner"
},
{
"name":"Fat Remover"
}
]
},
{
"name":"Others",
"children":[
{
"name":"Kitchen"
}
]
}
]
}
Is there an straight forward way to do this?
If it helps for anything, I need this to use as an entry for d3
libraries.
Thanks!