How to use the simplejson.JSONEncoder.default function in simplejson

To help you get started, we’ve selected a few simplejson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmoiron / speedparser / tests / speedparsertests.py View on Github external
def default(self, o):
        if isinstance(o, time.struct_time):
            return time.mktime(o)
        if isinstance(o, Exception):
            return repr(o)
        return json.JSONEncoder.default(self, o)
github zerovm / zerocloud / zerocloud / configparser.py View on Github external
def default(self, o):
        if isinstance(o, ZvmNode) or isinstance(o, ZvmChannel):
            return o.__dict__
        if isinstance(o, ObjPath):
            return o.url
        return json.JSONEncoder.default(self, o)
github flectra-hq / flectra / addons / rest_api / rest_exception.py View on Github external
def default(self, obj):
        if isinstance(obj, (bytes, bytearray)):
            return obj.decode("utf-8")
        return json.JSONEncoder.default(self, obj)
github StackStorm / st2 / st2common / st2common / util / jsonify.py View on Github external
def default(self, obj):  # pylint: disable=method-hidden
        if hasattr(obj, '__json__') and six.callable(obj.__json__):
            return obj.__json__()
        else:
            return JSONEncoder.default(self, obj)
github indico / indico / indico / util / json.py View on Github external
def default(self, o):
        if isinstance(o, _LazyString):
            return o.value
        elif isinstance(o, UserDict):
            return dict(o)
        elif isinstance(o, datetime):
            return {'date': str(o.date()), 'time': str(o.time()), 'tz': str(o.tzinfo)}
        elif isinstance(o, date):
            return str(o)
        return _json.JSONEncoder.default(self, o)
github ipeirotis / Mturk-Tracker / app / wapi / formatters / json_formatter.py View on Github external
def default(self, obj):
        try:
            return simplejson.JSONEncoder.default(self, obj)
        except TypeError:
            if isinstance(obj, Decimal):
                return float(obj)
            if isinstance(obj, datetime):
                return obj.strftime('%a, %d %b %Y %H:%M:%S %z')
            return smart_unicode(obj)
github ecdavis / pants / pants / web / application.py View on Github external
def default(self, o):
        if isinstance(o, datetime):
            return o.isoformat()
        return json.JSONEncoder.default(self, o)
github moskytw / mosql / mosql / json.py View on Github external
def default(self, obj):

        try:
            return json.JSONEncoder.default(self, obj)
        except TypeError, e:
            if isinstance(obj, (datetime, date)):
                return obj.isoformat()
            elif isinstance(obj, Model):
                return dict(obj)
            elif isinstance(obj, ColProxy):
                return list(obj)
            elif isinstance(obj, RowProxy):
                return dict(obj)
            else:
                raise e
github sprin / pg-discuss / blessed_extensions / unix_time_json_encoder.py View on Github external
def default(self, obj):
        if isinstance(obj, datetime.datetime):
            return (obj - EPOCH).total_seconds()
        return json.JSONEncoder.default(self, obj)
github okdistribute / papertalk / papertalk / utils / __init__.py View on Github external
def default(self, obj):
        if isinstance(obj, (datetime.datetime, datetime.date)):
            return obj.isoformat()
        elif isinstance(obj, ObjectId):
            return unicode(obj)
        return json.JSONEncoder.default(self, obj)