Skip to content

Instantly share code, notes, and snippets.

@dankohn
Last active December 18, 2015 16:38
Show Gist options
  • Save dankohn/5812440 to your computer and use it in GitHub Desktop.
Save dankohn/5812440 to your computer and use it in GitHub Desktop.
Parsing double-nested CSV fields
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