Im trying to store/load a dictionary of name: class to/from JSON but its not storing the dictionary variable from the class, just the other ones.
My class has
class Test():
a = ''
b = 0.0
c = {}
Ive tried using
class MyEncoder(json.JSONEncoder):
def default(self, o):
return o.__dict__
to encode it but __dict__ only returns the a and b variables. Im essentially doing
testDict = {}
test = Test()
testDict['a'] = test
test. a = 'asdf'
test.b = 1.4
test.c['qwert'] = 5
with open('test.json', 'w') as outfile:
output = json.dump(testDict, outfile, indent=3, cls=MyEncoder)
and when I try exporting to JSON it just exports everything but the dictionary
{
"a": {
"a": "asdf",
"b": 1.4
}
}
What do I need to do to export all of each instance of the class in my dictionary?