import csv
import json
csv_file = 'data.csv'
json_path = 'data.json'
data1 = {}
with open(csv_file) as data_csv:
csvRead = csv.DictReader(data_csv)
for csvrows in csvRead:
id = csvrows['row_id']
data[id] = csvrows
# Creating Multiple JSON files of 1000 rows each
i = 0
while i < len(data):
data_file = dict(list(data.items())[j:j+1000])
with open(json_path + "data" + str(j) + ".json", 'w') as data_json:
data_json.write(json.dumps(data1, indent=4))
i = i + 1000
The problem is I get output as
[ "1": { "id": 1, "name": "Smitraj", "Lastname":"Raut" } ]
But I don't want it in this format. I need the format as
[{ "id": 1, "name": "Smitraj", "Lastname":"Raut" } ]
data1which is not related to anything else in here, but that could not produce the output you claim you get, either.