Created
April 12, 2018 17:32
-
-
Save kirkness/85dead4a6d4adae4b1de275754317e1d to your computer and use it in GitHub Desktop.
Convert CSV to 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
const csvToJson = csv => { | |
const [firstLine, ...lines] = csv.split('\n'); | |
return lines.map(line => | |
firstLine.split(',').reduce( | |
(curr, next, index) => ({ | |
...curr, | |
[next]: line.split(',')[index], | |
}), | |
{} | |
) | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment