I have parsed a json file in python and have the results printed on screen.
However, I would also like the results to be output to a csv file, exactly as they appear on screen.
Here is my code:
import json
with open('euroinc.json') as json_data:
d = json.load(json_data)
for p in d['results']:
print(p['sedol']+','+p['company']+','+p['name']+','+ p['unitType']+','+p['perf48t60m']+','+p['perf36t48m']+','+p['perf24t36m']+','+p['perf12t24m']+','+p['perf12m']+','+p['initialCharge']+','+p['netAnnualCharge'])
Any help would be much appreciated! Thanks, Craig
Update: here is the json sample:
{
"results": [
{
"sector": "Europe Including UK",
"perf48t60m": "n/a",
"discountedCode": "",
"price_buy": "0",
"plusFund": false,
"unitType": "Accumulation",
"perf6m": "6.35%",
"perf36t48m": "11.29%",
"loaded": "Unbundled",
"fundSize": "2940.1",
"annualCharge": "1.07",
"netAnnualCharge": "1.07",
"sedol": "B7BW9Y0",
"perf24t36m": "0.25%",
"annualSaving": "0.00",
"updated": "06/09/2017",
"incomeFrequency": "N/a",
"perf60m": "n/a",
"perf12t24m": "12.97%",
"company": "BlackRock",
"initialCharge": "0.00",
"paymentType": "Dividend",
"perf3m": "0.32%",
"name": "BlackRock Global European Value (D2 GBP)",
"perf12m": "19.37%",
"price_change": "-39.00",
"yield": "0.00",
"price_sell": "6569.00",
"perf36m": "35.19%",
"numHoldings": "51"
},
{
"sector": "Europe Including UK",
"perf48t60m": "22.01%",
"discountedCode": "",
"price_buy": "0",
"plusFund": false,
"unitType": "Income",
"perf6m": "7.81%",
"perf36t48m": "9.61%",
"loaded": "Unbundled",
"fundSize": "566.1",
"annualCharge": "0.30",
"netAnnualCharge": "0.30",
"sedol": "B76VTR5",
"perf24t36m": "-3.95%",
"annualSaving": "0.00",
"updated": "06/09/2017",
"incomeFrequency": "Quarterly",
"perf60m": "77.38%",
"perf12t24m": "15.38%",
"company": "Vanguard",
"initialCharge": "0.00",
"paymentType": "Dividend",
"perf3m": "0.74%",
"name": "Vanguard SRI European Stock",
"perf12m": "19.69%",
"price_change": "-21.37",
"yield": "2.79",
"price_sell": "15800.81",
"perf36m": "32.65%",
"numHoldings": "502"
}
]
}