Skip to content

Instantly share code, notes, and snippets.

@oxr463
Last active June 15, 2020 23:42
Show Gist options
  • Save oxr463/dd646ad14da784fe4b184bedc3866faa to your computer and use it in GitHub Desktop.
Save oxr463/dd646ad14da784fe4b184bedc3866faa to your computer and use it in GitHub Desktop.
Convert CSV to JSON
#!/usr/bin/env node
// SPDX-License-Identifier: MIT
// Convert CSV to JSON
const csv2json = require("csvjson-csv2json");
const fs = require("fs");
const process = require("process");
const util = require("util");
process.argv.forEach(function (val, index, array) {
if(val.includes(".csv")) {
const csv = fs.readFileSync(val, "utf8");
const json = csv2json(csv);
// See: https://stackoverflow.com/a/48231698/8507637
console.log(util.inspect(json, { maxArrayLength: null }));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment