I can't figured out how to get the number values into a csv file in a col2 from the json file below. All I get is VAL1, VAL2, and VAL3 (see csv file sample at the end). I would like to get the json data like it is showing right below this text in the csv output file. Thank you so much for your help.
COL1,COL2
VAL1,123.777
VAL2,456.888
VAL3,789.999
file.json
{
"success": true,
"timestamp": 1663273564,
"source": "ABC",
"quotes": {
"VAL1": 123.777,
"VAL2": 456.888,
"VAL3": 789.999
}
}
Python export code:
import json
import csv
with open("C:file.json") as file:
data = json.load(file)
fname = "c:/output.csv"
with open(fname, "w") as file:
csv_file = csv.writer(file)
csv_file.writerow(["COL1","COL2"])
for item in data["quotes"]:
csv_file.writerow([item[0:4]])
output.csv file
COL1,COL2
VAL1
VAL2
VAL3
for item in data["quotes"].items():that should get you closer...csv_file.writerow(item)