How to convert CSV to JSON?

前端 未结 3 523
无人共我
无人共我 2020-12-19 21:03

I have a CSV file with the header as Key and the data as the Value. My goal is to convert the CSV file into Json to upload into a database and output the data I uploaded. I

3条回答
  •  猫巷女王i
    2020-12-19 21:48

    You are currently printing the result which is the dictionary itself, if you want to get the output in a nice format as shown in the question, you need to go through the dictionary to print out each key and its values

    for key in keys:  #looking through each key
        print (key)
        for i in results:  #going through the results and printing the value of the index with the current key
            print (results[i][key])
    

    This should give the expected output in the console as mentioned in question

提交回复
热议问题