While converting json file to csv,I got the above error My code is shown below:
import json
import csv
data = open("SRInFlow.json",encoding="utf8")
rows = json.loads(data.read())
r=rows.values()
fieldnames = [b'dateTimeValues', b'timeSeries']
with open('C:/DeepLearning/tensorflowpoc/Codes/SRInFlow.csv', 'w') as f:
dict_writer = csv.DictWriter(f, fieldnames=fieldnames)
dict_writer.writeheader()
for d in r:
---> dict_writer.writerow(d)
The error displays in the last line. How to rectify the error? Thanks in advance
r
andtype(r)
to get an idea what you are dealing with. $\endgroup$r = rows.values() ... for d in r:
is a really bad code-smell that you're trying to iterate over just the row values, yet expect them to behave like a dict(!) Why not just simply iterate the normal way:for row in rows:
$\endgroup$