I want to convert Json file to csv file using Pyhton
NickName:gemma Ask DateTime:2022-04-20T19:08:48

I want to convert Json file to csv file using Pyhton

I have problem when i convert json file to csv i convert my csv file to json and it work but when i convert json file to csv file it don't work!

HERE MY PYTHON CODE

   with open('orders.json') as json_file:
    data = json.load(json_file)
 
    order_data = data['orders']

    # now we will open a file for writing
    data_file = open('data_file.csv', 'w')

    # create the csv writer object
    csv_writer = csv.writer(data_file)

    # Counter variable used for writing
    # headers to the CSV file
    count = 0

    for ord in order_data:
        if count == 0:

            # Writing headers of CSV file
            header = ord.keys()
            csv_writer.writerow(header)
            count += 1

        # Writing data of CSV file
        csv_writer.writerow(ord.values())

    data_file.close()

and the output is like this

enter image description here

there null row on the csv file how to handle this problem?

and here the json file

enter image description here

Copyright Notice:Content Author:「gemma」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71938580/i-want-to-convert-json-file-to-csv-file-using-pyhton

More about “I want to convert Json file to csv file using Pyhton” related questions

I want to convert Json file to csv file using Pyhton

I have problem when i convert json file to csv i convert my csv file to json and it work but when i convert json file to csv file it don't work! HERE MY PYTHON CODE with open('orders.json') as

Show Detail

directly convert CSV file to JSON file using the Jackson library

I am using following code: CsvSchema bootstrap = CsvSchema.emptySchema().withHeader(); ObjectMapper mapper = new CsvMapper(); File csvFile = new File("input.csv"); // or from String, URL etc Objec...

Show Detail

Convert CSV to JSON file in python

Above csv file which contains nearly 2000 rows. I want to parse CSV file line by line and convert it to JSON and send over websocket. I found some code online which converts CSV to JSON as follo...

Show Detail

How to convert .csv file to json?

I need to read a .csv file and convert the csv file to json format and pass the json to frontend which is the best way to read a csv file and convert to json Here my code is: fs.readFile(req.files.

Show Detail

how to convert json file into csv file using unix shellscript or command-line?

i have file example.json file. but i want to convert into csv file, so on csv file i can insert the data into external table using postgresSQL. there is alternative way to convert it ? or there is ...

Show Detail

Convert json file to csv

I have this simple python code that converts a json file into a csv. I would like to convert only the first four values of each key, but i couldn't figure out how to do it. import json import csv ...

Show Detail

how to convert CSV file to json in flutter?

recently i develop an ToDo application using flutter and sqflite , for backup my data i convert my database data to csv file(import data to csv file using csv package) now i want to again use this ...

Show Detail

convert a CSV file to JSON file

I am trying to convert CSV file to JSON file based on a column value. The csv file looks somewhat like this. ID Name Age CSE001 John 18 CSE002 Marie ...

Show Detail

Convert csv to json returning empty json file

I am trying to convert a csv file to json using the convert-csv-to-json package from npm. I am able to get the csv from the url and the 'data.csv' is created, but the corresponding json file is jus...

Show Detail

Convert csv file to json object and save to file?

I am using https://github.com/Keyang/node-csvtojson to convert a csv file into json object but not sure how to create a js file from the output. Using the command $ csvtojson ./mycsv.csv I want t...

Show Detail