Skip to content Skip to sidebar Skip to footer

Nested Json To Csv Using Python Script

i'm new to python and I've got a large json file that I need to convert to csv - below is a sample { 'status': 'success','Name': 'Theresa May','Location': '87654321','AccountCatego

Solution 1:

This works for the JSON example you posted. The issue is that you have nested dict and you can't create sub-headers and sub rows for pcredit, pdebit, pbalance, ptransactiondate, pvaluedate and ptest as you want.

You can use csv.DictWriter:

import csv
import json

withopen("BankStatementJSON1.json", "r") as inputFile:  # open json file
    data = json.loads(inputFile.read())  # load json contentwithopen("testing.csv", "w") as outputFile:  # open csv file
    output = csv.DictWriter(outputFile, data.keys())  # create a writer
    output.writeheader()
    output.writerow(data)

Solution 2:

Post a Comment for "Nested Json To Csv Using Python Script"