as_json snippets

Ruby's as_json in Python

Tagged as_dict, as_json  Languages python
class Document():
    def as_dict(self, without=[]):
        res = {}
        for prop in vars(self):
            if prop in without:
                continue
            res[prop] = getattr(self, prop)
        return res

You could also simply implement and use dict, if without is not needed.