Last active
June 15, 2020 23:42
-
-
Save oxr463/dd646ad14da784fe4b184bedc3866faa to your computer and use it in GitHub Desktop.
Convert CSV to JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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