Reputation: 49
i am fetching currencies from the internet then trying to format them so every currency is on a new line, hoping someone could help me out
hoping to get an output something like this:
{
"AED" : "united Arab Emirates Dirham",
"AFN" : "Afghan Afghani",
...........
"ZWL" : "Zimbabwean Dollar"
}
My Code is as follows:
import json
import urllib.request
f = urllib.request.urlopen('http://www.maths.manchester.ac.uk/~mbbssvs4/python/currencies.json')
charset = f.info().get_param('charset', 'utf8')
data = f.read()
decoded = json.loads(data.decode(charset))
print(decoded)
Upvotes: 0
Views: 2240
Reputation: 17877
Try json.dumps
:
import json
j = json.loads("""{
"AED" : "united Arab Emirates Dirham",
"AFN" : "Afghan Afghani",
"ZWL" : "Zimbabwean Dollar"
}""")
print json.dumps(j, indent=4)
Output:
{
"AFN": "Afghan Afghani",
"ZWL": "Zimbabwean Dollar",
"AED": "united Arab Emirates Dirham"
}
https://docs.python.org/2/library/json.html
Upvotes: 2