Created
May 25, 2016 16:06
-
-
Save JuanjoSalvador/4d60cdd75b250340a4b702c9f1193fed to your computer and use it in GitHub Desktop.
Convertidor de CSV a JSON
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
//var csv is the CSV file with headers | |
function csvJSON(csv){ | |
var lines=csv.split("\n"); | |
var result = []; | |
var headers=lines[0].split(","); | |
for(var i = 1; i < lines.length; i++) { | |
var obj = {}; | |
var currentline = lines[i].split(","); | |
for(var j = 0; j < headers.length; j++) { | |
obj[headers[j]] = currentline[j]; | |
} | |
result.push(obj); | |
} | |
//return result; //JavaScript object | |
return JSON.stringify(result); //JSON | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment