Last active
December 18, 2015 16:38
-
-
Save dankohn/5812440 to your computer and use it in GitHub Desktop.
Parsing double-nested CSV fields
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 = require('csv') | |
var cat = "Text" | |
var commaCat = "A, B, and C" | |
var cat2 = "More text" | |
csv() | |
.from.array([[cat,commaCat,cat2]]) | |
.to.string( function(innerNest){ | |
console.log(innerNest) | |
csv() | |
.from.array([["1",innerNest,"2"]]) | |
.to.string( function(text){ | |
console.log(text) | |
csv() | |
.from.string(text) | |
.to.array( function(array) { | |
console.log(JSON.stringify(array)) | |
csv() | |
.from.string(array[0][1]) | |
.to.array( function(innerElement) { | |
console.log(JSON.stringify(innerElement[0][1])) | |
}) | |
}) | |
}, {quoted: true} ) | |
}, {quoted: true} ); | |
// $ node server/import/test_csv.js | |
// "Text","A, B, and C","More text" | |
// "1","""Text"",""A, B, and C"",""More text""","2" | |
// [["1","\"Text\",\"A, B, and C\",\"More text\"","2"]] | |
// "A, B, and C" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment