def to_json(obj, indent=4, sort_keys=True, **kwargs):
    """
    :param obj: object to convert to dictionary and then output to json
    :param indent: indent json by number of spaces
    :param sort_keys: sort json output by key if true
    :param kwargs: arguments to pass to to_dict
    :return: json string
    """
    obj_dict = to_dict(obj, **kwargs)
    return json.dumps(obj_dict, indent=indent, sort_keys=sort_keys)