def closest_value(archival_object, key):
    """Finds the closest value matching a key.

    Starts with an archival object, and iterates up through its ancestors
    until it finds a match for a key that is not empty or null.

    :param JSONModelObject archival_object: an ArchivesSpace archival_object.
    :param str key: the key to match against.

    :returns: The value of the key, which could be a str, list, or dict.
    :rtype: str, list, or key
    """
    if getattr(archival_object, key) not in ["", [], {}, None]:
        return getattr(archival_object, key)
    else:
        for ancestor in archival_object.ancestors:
            return closest_value(ancestor, key)