docstamp/file_utils.py
def csv_to_json(csv_filepath, json_filepath, fieldnames, ignore_first_line=True):
    """ Convert a CSV file in `csv_filepath` into a JSON file in `json_filepath`.

    Parameters
    ----------
    csv_filepath: str
        Path to the input CSV file.

    json_filepath: str
        Path to the output JSON file. Will be overwritten if exists.

    fieldnames: List[str]
        Names of the fields in the CSV file.

    ignore_first_line: bool
    """
    import csv
    import json

    csvfile = open(csv_filepath, 'r')
    jsonfile = open(json_filepath, 'w')

    reader = csv.DictReader(csvfile, fieldnames)
    rows = []
    if ignore_first_line:
        next(reader)

    for row in reader:
        rows.append(row)

    json.dump(rows, jsonfile)
    jsonfile.close()
    csvfile.close()
def csv_to_json(csv_filepath, json_filepath, fieldnames, ignore_first_line=True):
    import csv
    import json

    csvfile = open(csv_filepath, 'r')
    jsonfile = open(json_filepath, 'w')

    reader = csv.DictReader(csvfile, fieldnames)
    rows = []
    if ignore_first_line:
        next(reader)

    for row in reader:
        rows.append(row)

    json.dump(rows, jsonfile)
    jsonfile.close()
    csvfile.close()
def csv_to_json ( csv_filepath , json_filepath , fieldnames , ignore_first_line = True ) : import csv import json csvfile = open ( csv_filepath , 'r' ) jsonfile = open ( json_filepath , 'w' ) reader = csv . DictReader ( csvfile , fieldnames ) rows = [ ] if ignore_first_line : next ( reader ) for row in reader : rows . append ( row ) json . dump ( rows , jsonfile ) jsonfile . close ( ) csvfile . close ( )
Convert a CSV file in `csv_filepath` into a JSON file in `json_filepath`.

    Parameters
    ----------
    csv_filepath: str
        Path to the input CSV file.

    json_filepath: str
        Path to the output JSON file. Will be overwritten if exists.

    fieldnames: List[str]
        Names of the fields in the CSV file.

    ignore_first_line: bool
Convert a CSV file in csv_filepath into a JSON file in json_filepath .