def to_json(obj):
    """Utility method for converting an object to a json encoded string. 
    
    Takes care of all the necessary setup.
    
    Args:
        obj (object): The object that should be encoded.
        
    Returns:
        str: The encoded version of the given object.
    """
    import jsonpickle
    jsonpickle.set_encoder_options('simplejson', sort_keys=True)
    return jsonpickle.encode(obj, unpicklable=False)
