I have a file of nested json data. I am trying to "get.some_object" and write a csv file with the objects (I think they are called objects: "some_object": "some_value"); I would like one row for each group of nested items. This is my code:
import csv
import json
path = 'E:/Uni Arbeit/Prof Hayo/Sascha/Bill data/97/bills/hr/hr4242'
outputfile = open('TaxLaw1981.csv', 'w', newline='')
outputwriter = csv.writer(outputfile)
with open(path + "/" + "/data.json", "r") as f:
data = json.load(f)
for act in data['actions']:
a = act.get('acted_at')
b = act.get('text')
c = act.get('type')
outputwriter.writerow([a, b, c])
outputfile.close()
The problem I have is that it only writes the last group of data to csv; however when I run
with open(path + "/" + "/data.json", "r") as f:
data = json.load(f)
for act in data['actions']:
a = act.get('acted_at')
b = act.get('text')
c = act.get('type')
print (a)
all of my "a" values print out.
Suggestions?