Skip to content

Instantly share code, notes, and snippets.

@AndresMWeber
Created October 7, 2019 17:41
Show Gist options
  • Save AndresMWeber/ebb437bf2c408a81cb8b1fb4cfa41471 to your computer and use it in GitHub Desktop.
Save AndresMWeber/ebb437bf2c408a81cb8b1fb4cfa41471 to your computer and use it in GitHub Desktop.
Convert CSV to JSON Example
/**
* This is meant to be run on data.csv coming in from Talal. It only converts to JSON and hardcodes the filepath.
*/
function convertCSVtoJSON() {
csv()
.fromFile('data.csv')
.then((crimeDataSet) => {
fs.writeFile("data.json", JSON.stringify(crimeDataSet), 'utf8', function(err) {
if (err) {
console.log("An error occurred while writing JSON Object to File.");
return console.log(err);
}
console.log("JSON file has been saved.");
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment