我想将csv
转换为多级json
。我想要的只是来自:
brand, active, prod , prod_id, part, part_id, part_prise
canon, 1 , camera , 132 , body, 543 , 399
canon, 0 , camera , 132 , lens, 543 , 399
canon, 1 , printer, 132 , cart, 543 , 399
canon, 1 , printer, 872 , ink , 543 , 399
sony , 1 , camera , 132 , body, 543 , 399
sony , 1 , lcd , 112 , body, 543 , 399
sony , 0 , lcd , 132 , body, 543 , 399
sony , 1 , laptop , 162 , body, 543 , 399
以下应该是它的JSON文件。
brand : "canon",
active : 1,
prod : [{
prod : "camera",
prod_id : 132,
part : [{
part : "body",
part_id : 543,
part_prise:399
},
{
part : "lens",
part_id : 543,
part_prise:399
}]
},{
prod : "printer",
prod_id : 132,
part : [{
part : "cart",
part_id : 543,
part_prise:399
},
{
part : "ink",
part_id : 543,
part_prise:399
}]
}
]
...
...
...and so on..
答案 0 :(得分:1)
使用csv dictreader,它在python csv包中出现