def all_values(json_rec, field_name, subfield_name=None):
    """
    This is a helper function that, given a field name, returns an iterator over all values in the field regardless of
    if the field contains an array or a single value.
    :param json_rec: JSON record
    :param field_name: field to contain either array or a single value
    :return: iterator over the values
    """
    if field_name not in json_rec:
        return
    field = json_rec[field_name][subfield_name] if subfield_name else json_rec[
        field_name]
    if isinstance(field, list):
        for k in field:
            yield k
    else:
        yield field
