Nov-02-2020, 09:16 AM
Hello Friends,
I am still a learner of Python and I have a situation where I have to convert my CSV to Json. I understand how we can convert direct CSV row to json format. But I am struggling to understand how I can convert multiple rows in a column to multiple items in json. Please help.
Thanks
Below is my scenario.
Source CSV:
Type 1:
deptno, deptname, client name, client dob, client phone, client email
"100", "Sales", "ABC", "01011980", "0282200222;0729282929", "[email protected]"
Type 2:
deptno, deptname, client name, client dob, client phone, client email
"100", "Sales", "ABC", "01011980", "0282200222", "[email protected]"
"100", "Sales", "ABC", "01011980", "0729282929", "[email protected]"
Required Target in json:
{
"deptno": "100",
"deptname": "Sales",
"client": {
"name": "ABC",
"dob": "01011980",
"contact": [{
"TYPE": "PHONE",
"VALUE": "0282200222"
},
{
"TYPE": "PHONE",
"VALUE": "0729282929"
}
{
"TYPE": "email",
"VALUE": "[email protected]"
}
],
}
}
I am still a learner of Python and I have a situation where I have to convert my CSV to Json. I understand how we can convert direct CSV row to json format. But I am struggling to understand how I can convert multiple rows in a column to multiple items in json. Please help.
Thanks
Below is my scenario.
Source CSV:
Type 1:
deptno, deptname, client name, client dob, client phone, client email
"100", "Sales", "ABC", "01011980", "0282200222;0729282929", "[email protected]"
Type 2:
deptno, deptname, client name, client dob, client phone, client email
"100", "Sales", "ABC", "01011980", "0282200222", "[email protected]"
"100", "Sales", "ABC", "01011980", "0729282929", "[email protected]"
Required Target in json:
{
"deptno": "100",
"deptname": "Sales",
"client": {
"name": "ABC",
"dob": "01011980",
"contact": [{
"TYPE": "PHONE",
"VALUE": "0282200222"
},
{
"TYPE": "PHONE",
"VALUE": "0729282929"
}
{
"TYPE": "email",
"VALUE": "[email protected]"
}
],
}
}