Created
December 2, 2017 10:59
-
-
Save jsmrcaga/f3cf37382b38351fc58dfe5bd93892ff to your computer and use it in GitHub Desktop.
This file contains 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
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