[PYTHON]: Here's a class to clean JSON data

Hello Everyone, I was working on a new use case and I continually find myself trying to clean JSON data from integrations (including converting timestamps) so I wrote this CleanJson python class:

class CleanJson(object):

    def __init__(self, data):
            json_data = json.dumps(data, default=self.json_serial)
            self.decoded_dict = json.loads(json_data, object_hook=self.decode_dict)
            json_data = json.dumps(data, default=self.json_serial)
            self.decoded_list = json.loads(json_data, object_hook=self.decode_dict)

    def get(self):
        if self.decoded_dict:
            return self.decoded_dict
        elif self.decoded_list:
            return self.decoded_list

    def json_serial(self, obj):
        """JSON serializer for objects not serializable by default json code"""
        if isinstance(obj, date) or isinstance(obj, datetime):
            return obj.isoformat()
        raise TypeError ("Type %s not serializable" % type(obj))

    def decode_list(self, data):
        rv = []
        for item in data:
            if isinstance(item, unicode):
                item = item.encode('utf-8')
            elif isinstance(item, list):
                item = self.decode_list(item)
            elif isinstance(item, dict):
                item = self.decode_dict(item)
        return rv

    def decode_dict(self, data):
        rv = {}
        for key, value in data.iteritems():
            if isinstance(key, unicode):
                key = key.encode('utf-8')
            if isinstance(value, unicode):
                value = value.encode('utf-8')
            elif isinstance(value, list):
                value = self.decode_list(value)
            elif isinstance(value, dict):
                value = self.decode_dict(value)
            rv[key] = value
        return rv

You can call it by just passing in return data from an integration or another method:

data = CleanJson(call_some_integration_method(var1, var2))

And it will return clean json