JSONEncoder is not being called

Viewed 277

I am trying to encode JSON with json.JSONEncoder with another pattern by overriding the default method:

class X(json.JSONEncoder):
    def default(self, obj):
        return ["ok"]

json.dumps(self, cls=X)

But the default method is not being called... I saw a few examples who looks like this, but I can't figure out what is missing?

currently, I get my json as {"status": "Fail"}

Note: followed this link.

I am using python 3.6 Thank you

1 Answers

I found the problem. my object was inherited from dict, while default method is not being called on object like dict and list

Related