I'm think what I'm trying to do is very simple. I'm converting .json to a .csv file, but struggling to get exactly what I want. I'm sure I'm being silly, but can't find an answer on this site. Please point out what my silly mistake is!
I'm using the following Python code:
import csv, json
inputFile = open('results_20190214b.txt') outputFile = open('results_20190214.csv', 'w', newline='')
data = json.load(inputFile) inputFile.close
output = csv.writer(outputFile)
for row in data:
output.writerow([row])
outputFile.close()
My json looks like this:
{
"AccumulatedNewCapacity[UTOPIA,E01,1999]": {
"Value": 0.0225798659394097
},
"AccumulatedNewCapacity[UTOPIA,E01,2000]": {
"Value": 0.149302162579271
},
"AccumulatedNewCapacity[UTOPIA,E01,2001]": {
"Value": 0.354595177554284
},
"AccumulatedNewCapacity[UTOPIA,E01,2002]": {
"Value": 0.553976916527268
},
"AccumulatedNewCapacity[UTOPIA,E01,2003]": {
"Value": 0.749394931502283
}, ETC
This code is successfully printing the field names to the CSV, but I am not getting any of the values. E.g:
AccumulatedNewCapacity[UTOPIA,E01,1999]
AccumulatedNewCapacity[UTOPIA,E01,2000]
AccumulatedNewCapacity[UTOPIA,E01,2001]
Any ideas greatly appreciated. Thanks!