我正在使用python将复杂的json转换为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...
我编写的代码如下: 我的python代码:
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())
但是我没有在csv文件中获得正确的输出只获得一行但完整的json不会出现