I am trying to write a json dump of a list of objects to file. The object looks like this:
class Pokemon:
def __init__(self, id, names, genus = None):
self.id = id
self.names = names
def dict(self):
return OrderedDict([("id", self.id), ("names", self.names)]) #force specific key order
self.names
is a dictionary containing a language id and a corresponding name, some of them in Japanese, Korean and Chinese. Later on in my code, I save the list to JSON like this:
with codecs.open("pkmn.json", "w", encoding="utf8") as outfile:
json.dump([p.dict() for p in pokemon], outfile, indent = 2)
But instead of "フシギダネ", "이상해씨", and "妙蛙種子", I get unreadable gibberish, as shown below.
How can I get Python to properly save those strings to file?