Convert CSV to JSON using Python
CSV (or Comma Separated Value) files represent data in a tabular format, with several rows and columns. An example of a CSV file can be an Excel Spreadsheet. These files have the extension of .csv, for instance, geeksforgeeks.csv. In this sample file, every row will represent a record of the dataset, and each column will indicate a unique feature variable.
Refer to the below articles to understand the basics of JSON and CSV.
Converting CSV to JSON
We will create a JSON file that will have several dictionaries, each representing a record (row) from the CSV file, with the Key as the column specified.
Sample CSV File used:
) as csvf:
) as jsonf: