def constraint_to_dict(constraint):
    """
    Tries to convert the object to a dictionary using its
    json() method if it exists.
    Otherwise, it assumes that already is a dictionary and return it as is.
    """
    try:
        return constraint.json()
    except AttributeError:
        return constraint
