Skip to content

Instantly share code, notes, and snippets.

@jsmrcaga
Created December 2, 2017 10:59
Show Gist options
  • Save jsmrcaga/f3cf37382b38351fc58dfe5bd93892ff to your computer and use it in GitHub Desktop.
Save jsmrcaga/f3cf37382b38351fc58dfe5bd93892ff to your computer and use it in GitHub Desktop.
const fs = require('fs');
console.time('Reading CSV...');
let csv = fs.readFileSync('./rocket.csv', {encoding: 'utf8'});
console.timeEnd('Reading CSV...');
let lines = csv.split('\n');
let names = lines.splice(0,1)[0].split(';');
console.log('Got names', names.join(', '));
console.log('And', lines.length, 'lines');
console.time('Mapping elements');
let json = lines.map(e => {
return e.split(';');
}).map(e => {
let obj = {};
e.map((v,i) => {
obj[names[i]] = v;
});
return obj;
});
console.timeEnd('Mapping elements');
fs.writeFileSync('./unis.json', JSON.stringify(json));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment