Convert CSV data to JSON with gobble.
First, you need to have gobble installed - see the gobble readme for details. Then,
npm i -D gobble-csvtojson
var gobble = ;moduleexports =;
The second argument is optional:
true, values will be parsed with
JSON.parse()- e.g. numbers will be stored as numbers,
falsewill be stored as booleans, and so on. Otherwise, all values will be stored as strings
nullor missing values will not be added to objects
JSON.stringify(), useful if readability is more important than the filesize of the resulting JSON
This isn't using a robust, battle-tested CSV parser - it's using a few brittle hacks (I needed something quickly and didn't have time to evaluate all the options). Contributions welcome!
Your CSV is expected to be well-formed, and to have a header row (headers become the keys of each JSON object).
It goes something like this - CSV goes in...
...JSON comes out. Note that the IDs are numeric, and Randy doesn't have an
(Mock data via mockaroo.com.)
MIT. Copyright 2014 Rich Harris