$1.10 $0.00
This ChatGPT prompt is writing a Python code that can extract data from a CSV file and save it as a JSON file. CSV (Comma Separated Values) is a commonly used format for storing and exchanging data in a tabular form, while JSON (JavaScript Object Notation) is a lightweight data interchange format that is widely used in web applications.
I want you to act as a programmer and write a Python code that extracts data from a CSV file and saves it as a JSON file.
import csv
import json
# Open the CSV file
with open('input.csv', 'r') as csv_file:
# Parse the CSV file with a comma delimiter
csv_reader = csv.DictReader(csv_file, delimiter=',')
# Create an empty list to hold the data
data = []
# Loop through each row in the CSV file
for row in csv_reader:
# Append the row to the list
data.append(row)
# Open a new JSON file
with open(‘output.json’, ‘w’) as json_file:
# Write the data to the JSON file
json.dump(data, json_file)
Please use this prompt responsibly
Share your creations with your community
All the prompts are for educational purposes