I'm attempting to recreate the following JSON using python classes with inheritence :
{"attribute1": "c1"
"attribute2": {"attribute3" : "test"}
}
So far I have this code:
class class1():
def __init__(self, attribute1):
self.attribute1 = attribute1
class class2(class1):
def __init__(self, attribute2):
class1.__init__(self, 'test')
self.attribute2 = attribute2
c1 = class1('c1')
c2 = class2(c1)
print(json.dumps(c1.__dict__))
renders:
{"attribute1": "c1"}
If I try to convert the variable c2 to JSON:
print(json.dumps(c2.__dict__))
I receive error:
TypeError: Object of type class1 is not JSON serializable
Shouldn't class1 be serializable as I convert it previously using print(json.dumps(c1.__dict__))