CSV to JSON Converter
This project contains a simple Python script that converts a CSV file into a JSON file. It is useful because JSON is easier and faster to work with in many cases.
What the script does
Reads a .csv file
Converts all rows into JSON format
Saves the result as output.json
Very easy and beginner-friendly
How to use it
Put your CSV file in the same folder as file.py.
Open PowerShell or Terminal in that folder.
Run this command:
python file.py
After running, a file called output.json will be created.
Code used in file.py import csv import json
input_file = "yourfile.csv" # change this to your CSV file name output_file = "output.json"
with open(input_file, "r", encoding="utf-8") as csv_file: reader = csv.DictReader(csv_file) data = list(reader)
with open(output_file, "w", encoding="utf-8") as json_file: json.dump(data, json_file, indent=4, ensure_ascii=False)
print(" Converted:", input_file, "→", output_file)
Example CSV: Title,Author,Year AI Basics,John Doe,2023
JSON: [ { "Title": "AI Basics", "Author": "John Doe", "Year": "2023" } ]
Notes
Make sure the CSV file name in the script matches the real name of your CSV file.
Only built-in Python libraries are used.