def list_to_comma_string(val, file_format):
    """
    Handle array fields by converting them to a comma-separated string.

    Example:
        ['1','2','3'] -> 1,2,3
    """

    if val is None:
        # If a field is empty we must replace it with an empty string for tsv/csv exports and leave it as None for json exports
        if file_format == "json":
            return val
        return ""

    if isinstance(val, list):
        val = ",".join(val)
    return val