Python Forum
Conversion CSV to JSON - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Conversion CSV to JSON (/thread-31909.html)



Conversion CSV to JSON - mati - Jan-09-2021

Hello Everyone,
I'm new here.
I'm looking for help in my code.
I'm writting app to convert csv to json file and i did the conversion but final .json file looks like this:
Quote:{
"asset_id": {
"0": 9,
"1": 10,
"2": 11,
"3": 12,
"4": 13,
"5": 14,
"6": 15,
Insted of this:
Quote:[
{"asset_id": 9,
"content_id": 0,
"os": [1.0,
1.0,
1.0,
2.0,
1.0,
1.0,
1.0,
1.0,
1.0,
3.0,
1.0,
2.0,
2.0,
1.0,
1.0,
1.0,
2.0,
1.0,
1.0,
2.0,
1.0,
1.0,
1.0,
1.0,
1.0,
2.0,
4.0,
2.0,
5.0,
2.0],
"path": "/BigBuckBunny_20_288_375.yuv"
And my code to do conversion is:

import tkinter as tk                                         # Declaration of the library needed to create the graphical interface.
from tkinter import filedialog                                  
from tkinter import messagebox
import pandas as pd                                          # Library declaration for data handling.
def convertToJSON ():                                                               # Function that converts a .csv file to a .json file.
    global read_file
    
    export_file_path = filedialog.asksaveasfilename(defaultextension='.json')
    read_file.to_json (export_file_path)
I was trying to rearrange the file after but it wasnt working.
Can anyone help?
Sorry for mistakes in this post, but its my first time Confused


RE: Conversion CSV to JSON - jefsummers - Jan-09-2021

With the limited code sample, not sure what your file looks like that you have read. It is also generally a bad idea to pass arguments to your function by global rather than as actual arguments.