def json_repr(obj, curr_depth=0, max_depth=4):
    """Represent instance of a class as JSON.
    Arguments:
    obj -- any object
    Return:
    String that represent JSON-encoded object.
    """
    def serialize(obj, curr_depth):
        """Recursively walk object's hierarchy. Limit to max_depth"""
        if curr_depth>max_depth:
            return
        if isinstance(obj, (bool, int, long, float, basestring)):
            return obj
        elif isinstance(obj, dict):
            obj = obj.copy()
            for key in obj:
                obj[key] = serialize(obj[key], curr_depth+1)
            return obj
        elif isinstance(obj, list):
            return [serialize(item, curr_depth+1) for item in obj]
        elif isinstance(obj, tuple):
            return tuple(serialize([item for item in obj], curr_depth+1))
        elif hasattr(obj, '__dict__'):
            return serialize(obj.__dict__, curr_depth+1)
        else:
            return repr(obj) # Don't know how to handle, convert to string

    return (serialize(obj, curr_depth+1))
def json_repr(obj, curr_depth=0, max_depth=4):
    """Represent instance of a class as JSON.
    Arguments:
    obj -- any object
    Return:
    String that represent JSON-encoded object.
    """
    def serialize(obj, curr_depth):
        """Recursively walk object's hierarchy. Limit to max_depth"""
        if curr_depth>max_depth:
            return
        if isinstance(obj, (bool, int, long, float, basestring)):
            return obj
        elif isinstance(obj, dict):
            obj = obj.copy()
            for key in obj:
                obj[key] = serialize(obj[key], curr_depth+1)
            return obj
        elif isinstance(obj, list):
            return [serialize(item, curr_depth+1) for item in obj]
        elif isinstance(obj, tuple):
            return tuple(serialize([item for item in obj], curr_depth+1))
        elif hasattr(obj, '__dict__'):
            return serialize(obj.__dict__, curr_depth+1)
        else:
            return repr(obj) # Don't know how to handle, convert to string

    return (serialize(obj, curr_depth+1))
def json_repr ( obj , curr_depth = 0 , max_depth = 4 ) : def serialize ( obj , curr_depth ) : """Recursively walk object's hierarchy. Limit to max_depth""" if curr_depth > max_depth : return if isinstance ( obj , ( bool , int , long , float , basestring ) ) : return obj elif isinstance ( obj , dict ) : obj = obj . copy ( ) for key in obj : obj [ key ] = serialize ( obj [ key ] , curr_depth + 1 ) return obj elif isinstance ( obj , list ) : return [ serialize ( item , curr_depth + 1 ) for item in obj ] elif isinstance ( obj , tuple ) : return tuple ( serialize ( [ item for item in obj ] , curr_depth + 1 ) ) elif hasattr ( obj , '__dict__' ) : return serialize ( obj . __dict__ , curr_depth + 1 ) else : return repr ( obj ) # Don't know how to handle, convert to string return ( serialize ( obj , curr_depth + 1 ) )
Represent instance of a class as JSON.
    Arguments:
    obj -- any object
    Return:
    String that represent JSON-encoded object.
Represent instance of a class as JSON . Arguments : obj -- any object Return : String that represent JSON - encoded object .