Toggle menu

csv

The csv package contains four modules which can generate, parse, stringify and transform csv text and JavaScript arrays and objects.

This library is distributed under the MIT license, its source is https://www.npmjs.com/package/csv For full documentation see https://csv.js.org

Executed

Server-side

Details

var csv = require('csv');

Although split into four packages, all are available from the single 'require' function, with each passed as a method, ie csv.generate, csv.parse, csv.stringify and csv.transform.

Example - Basic Parse

function(params, credentials) {
    var csv = require('csv');
    var input = 'My Data\n"1","2","3","4"\n"a","b","c","d"';
    var result = csv.parse(input);
    return result;
}

{
    "jsonrpc": "2.0",
    "id": 140,
    "result": [
        ["My Data"],
        ["1", "2", "3", "4"],
        ["a", "b", "c", "d"]
    ]
}

Example 2 - Individual Packages and Options

function(params, credentials) {
    var csv = require('csv-parse/lib/sync');
    var input = 'My Data1,My Data2,My Data3,My Data4\n"1","2","3","4"';
    var result = csv(input, {
        columns: true
    });
    return result;
}

{
    "jsonrpc": "2.0",
    "id": 28,
    "result": [{
        "My Data1": "1",
        "My Data2": "2",
        "My Data3": "3",
        "My Data4": "4"
    }]
}

Last modified on March 10, 2020

Share this page

Facebook icon Twitter icon email icon

Print

print icon