patx/pickledb

pass in a json encoder function to json.dumps

academyofzhuang opened this issue · 0 comments

json.dumps can't serialize user defined instance variables. If you allow us to pass in configuration to json.dumps, we can solve the problem.

def my_instance_json_encoder(x):
    lambda x: x.__dict__


s = json.dumps(
        users, default=my_instance_json_encoder
)

Better yet:

config = {
    "default": lambda x: x.__dict__,
    "indent": "    ",
}

 json.dumps(users, config)