Converting CSV to JSON in Python

Ashley Kwon (Spring 2023)

This tutorial explains how to convert a CSV file into a JSON file using a Python program. Doing so will be useful when you want to open a file that contains integer, float, and string data entries in a Unity project.

4. In the for loop from the code snippet above, line refers to one line in your csv file. You can access its individual data entries as if you're accessing elements in a list in Python. For example, the 2nd entry in line would be line[1]

5. Store the data you read from each line in your csv file into the dictionary object you made in 2. Since this object is a dictionary, you'll need a key and a value for each entry. These key-value pairs will differ based on how you want to store your JSON file.

6. After your for loop finishes iterating, your dictionary object should have all data you want to store. Save your dictionary object as a json file using the following lines: