Convert CSV to JSON using Python

mahabub.devs3
Mahabubur Rahman
Published on Oct, 19 2024 1 min read 0 comments
image

import csv import json
def csv_to_json(csv_file, json_file):
	with open(csv_file, mode='r') as file: 
		csv_reader csv.DictReader (file)
		data = [row for row in csv_reader]
		
	with open(json_file, mode= 'w') as file:
		json.dump(data, file, indent=4)
	
	print(f"CSV to JSON conversion completed successfully! {json_file}")
csv_to_json('sumecsv.csv', 'convertedfile.json')
CSV to JSON conversion completed! convertedfile.json
0 Comments