import csv
import io
import json


def generate_crash_record(line, fieldnames):
    """
    Translates a raw csv line into a python dictionary
    :param line: string - The raw csv line
    :param fieldnames: array of strings - The strings to be used as headers
    :return: dict
    """
    reader = csv.DictReader(
        f=io.StringIO(line), fieldnames=fieldnames, delimiter=","
    )  # parse line
    fields = json.dumps([row for row in reader])  # Generate json
    # Remove object characters
    fields = fields.replace("[", "").replace("]", "")
    # Return a dictionary
    return json.loads(fields)