import csv
import io
import json


def csv_to_dict(line, fieldnames):
    """
    Turns a csv line into a dictionary
    :param str line: A comma-separated line
    :param str[] fieldnames: An array of strings containing the headers for each column to be used as keys.
    :return dict:
    """
    reader = csv.DictReader(
        f=io.StringIO(line),
        fieldnames=list(map(lambda x: x.lower(), fieldnames)),
        delimiter=",",
    )  # parse line
    return json.dumps([row for row in reader])