convert dsv files to javascript objects

Usage no npm install needed!

<script type="module">
  import dsvToObjects from 'https://cdn.skypack.dev/dsv-to-objects';


DSV to Objects

Easily convert DSV string, files, and online resources into an array of javascript objects. This will take the first line of your DSV file and use it as your new objects keys and every subsequent line will be converted to a new object.


Available through npm, just run npm install dsv-to-objects


The default delimiter will be a comma followed by NOT whitespace

var dsvToObjects = require('dsv-to-objects');

var string = 'foo,bar,baz\nlorem,ipsum,dolor';
var filePath = 'path/to/file.csv';
var url = 'http://download/file.csv';
var callback = function(body) {

// Call with a string

// Call with a file path

// Call with a url, this is async and requires a callback and at least and empty options object
dsvToObjects.buildObjectsFromUrl(url, {}, callback);

#=> { "foo": "lorem", "bar": "ipsum", "baz": "dolor" }

All three methods also support an object of options

buildObjectsFromString(string, {delimiter: delimiter, toRemove: toRemove})

delimiter: whatever your chosen delimiter is, takes a string or regex

toRemove: an array of characters you want to remove from your dsv file

var dsvToObjects = require('dsv-to-objects');

var string = 'foo\tbar\tbaz\nAlorem\tAipsum\tAdolor';

// Call with string, tab delimited, and remove capital 'A' characters
dsvToObjects.buildObjectsFromString(string, {delimiter: "\t", toRemove: ["A"]);

#=> { "foo": "lorem", "bar": "ipsum", "baz": "dolor" }