I'm trying to run the json.dumps method on a nested class/object and it fails on TypeError: <__main__.nested_object object at 0x...> is not JSON serializable
What should I change in my class so I could call json.dumps method with input parameters of an implementation of JSONEncoder?
Here is a very simple code that simulate the problem:
class leaf_object(object):
def __init__(self, s):
self.value = s
class nested_object(object):
def __init__(self, a, b_list):
self.a = a
self.b_list = b_list
if __name__ == "__main__":
obj = nested_object('a1', [leaf_object('a1.1'),leaf_object('a1.2')])
import json
print(json.dumps(obj))