Python Forum

Full Version: Conversion CSV to JSON
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.