Convert CSV to JSON with Python

Convert CSV to JSON with Python

I got help from a youtube tutorial linked below

  1. import csv and import json packages
  2. Create a file path to your CSV file: csvFilePath = ?csv_file_name.csv?
  3. Create a file path to your JSON file: jsonFilePath = ?json_file_name.json?
  4. Create an empty dictionary to store your converted JSON data: data = {}
  5. Open and read the CSV:

Image for postOpen and read CSV file

7. Create a JSON file with the file path from step 3 to write converted data on

Image for postCreate new JSON file and write on it

Final code snippet

Image for postFinal code example

Note to self:

Dictionaries ? maps a set of objects (keys) to another set of objects (values).

  • Use {} to create a dictionary and to index it.
  • Separate key and value pairs with : and commas between each key pair

YouTube tutorial ? thank you ProProgramming101

1

No Responses

Write a response