Function CSVToJSON

  • Converts a comma-separated string of values (CSV) to an array of 2D objects. The first line of the string is used as the header line.

    Parameters

    • data: string

      csv data

    • delimiter: string = ','

      delimiter, default ','

    Returns any[]

    • json
    CSVToJSON('col1,col2\\na,b\\\nc,d')
    // `[{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]`.

    CSVToJSON('col1;col2\\\na;b\\\nc;d', ';')
    // `[{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]`.

    1.0.9