vdb/lib/utils.py
def dump(obj):
    """Dumps a python object to a JSON string. Argument: Python object"""

    def _dump(obj, path):
        if isinstance(obj, list):
            li = []
            i = 0
            for item in obj:
                li.append(_dump(item, path + "/[" + str(i) + "]"))
                i += 1
            return li
        elif isinstance(obj, Enum):  # Enum
            d = {}
            d["type"] = obj.__class__.__name__
            d["value"] = obj.value
            return d
        elif isinstance(obj, dict):  # dict
            rd = {}
            for key in obj:
                rd[key] = _dump(obj[key], path + "/" + key)
            return rd
        elif isinstance(obj, datetime):  # datetime
            d = {}
            d["type"] = obj.__class__.__name__
            if hasattr(obj, "isoformat"):
                d["value"] = obj.isoformat()
            else:
                d["value"] = obj.strftime(date_format_str)
            return d
        elif (
            isinstance(obj, str)
            or isinstance(obj, int)
            or isinstance(obj, float)
            or isinstance(obj, complex)
            or isinstance(obj, bool)
            or type(obj).__name__ == "NoneType"
        ):
            return obj
        else:
            d = {}
            d["type"] = obj.__class__.__name__
            for key in obj.__dict__:
                d[key] = _dump(obj.__dict__[key], path + "/" + key)
            return d

    return _dump(obj, "/")
Dumps a python object to a JSON string. Argument: Python object
Dumps a python object to a JSON string. Argument: Python object
Dumps a python object to a JSON string . Argument : Python object
def dump(obj):
    def _dump(obj, path):
        if isinstance(obj, list):
            li = []
            i = 0
            for item in obj:
                li.append(_dump(item, path + "/[" + str(i) + "]"))
                i += 1
            return li
        elif isinstance(obj, Enum):  
            d = {}
            d["type"] = obj.__class__.__name__
            d["value"] = obj.value
            return d
        elif isinstance(obj, dict):  
            rd = {}
            for key in obj:
                rd[key] = _dump(obj[key], path + "/" + key)
            return rd
        elif isinstance(obj, datetime):  
            d = {}
            d["type"] = obj.__class__.__name__
            if hasattr(obj, "isoformat"):
                d["value"] = obj.isoformat()
            else:
                d["value"] = obj.strftime(date_format_str)
            return d
        elif (
            isinstance(obj, str)
            or isinstance(obj, int)
            or isinstance(obj, float)
            or isinstance(obj, complex)
            or isinstance(obj, bool)
            or type(obj).__name__ == "NoneType"
        ):
            return obj
        else:
            d = {}
            d["type"] = obj.__class__.__name__
            for key in obj.__dict__:
                d[key] = _dump(obj.__dict__[key], path + "/" + key)
            return d
    return _dump(obj, "/")
def dump ( obj ) : def _dump ( obj , path ) : if isinstance ( obj , list ) : li = [ ] i = 0 for item in obj : li . append ( _dump ( item , path + "/[" + str ( i ) + "]" ) ) i += 1 return li elif isinstance ( obj , Enum ) : d = { } d [ "type" ] = obj . __class__ . __name__ d [ "value" ] = obj . value return d elif isinstance ( obj , dict ) : rd = { } for key in obj : rd [ key ] = _dump ( obj [ key ] , path + "/" + key ) return rd elif isinstance ( obj , datetime ) : d = { } d [ "type" ] = obj . __class__ . __name__ if hasattr ( obj , "isoformat" ) : d [ "value" ] = obj . isoformat ( ) else : d [ "value" ] = obj . strftime ( date_format_str ) return d elif ( isinstance ( obj , str ) or isinstance ( obj , int ) or isinstance ( obj , float ) or isinstance ( obj , complex ) or isinstance ( obj , bool ) or type ( obj ) . __name__ == "NoneType" ) : return obj else : d = { } d [ "type" ] = obj . __class__ . __name__ for key in obj . __dict__ : d [ key ] = _dump ( obj . __dict__ [ key ] , path + "/" + key ) return d return _dump ( obj , "/" )
Dumps a python object to a JSON string.
Dumps a python object to a JSON string .
"""Dumps a python object to a JSON string. Argument: Python object""" # Enum # dict # datetime
obj