I am using python to convert complex json into csv
I want to convert complex json into csv using python
sample json :
{
"data":[
{
"filter":"tags",
"cost":1234,
"values":[
{
"count":13,
"subvalues":[
{
"count":1,
"subvalue":"goat",
"cost":227.576
},
"storage":[
{
"resource_id":"1234343413",
"cost":25.047,
"running_hours %":61.52777777777778,
"created_in":"asd ",
"account_name":null,
"service":"csdsae",
etcc...
I have written the code as below: my python code :
import json
import csv
f = open('file.json')
data = json.load(f)
s=csv.writer(open('test6.csv','w'))
count = 0
for item in data["breakdown"]:
s.writerow([item])
if count == 0:
header = item.keys()
s.writerow(header)
count += 1
s.writerow(item.values())
But i am not getting proper output in csv file getting only one line but the complete json is not coming