I have a csv file with those data:
DBL ;1/6/2024;21;
DBL ;2/6/2024;20;
FAM ;1/6/2024;22;
FAM ;2/6/2024;18;
And i want to convert it to json with this format:
{
"DBL": [
{"date":"2024-06-01","allot":21},
{"date":"2024-06-02","allot":20}
]
"FAM": [
{"date":"2024-06-01","allot":22},
{"date":"2024-06-02","allot":18}
]
}
Here is my code:
import csv
import json
with open('CNLALLOT.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
data = list(csv_reader)
with open('CNLALLOT.json', 'w') as json_file:
json.dump(data, json_file, indent=4)