wdavidw/node-csv — pull request #160 by tobymarsden (2014-03-22 14:34:58+00:00)
Title: Add preserveObjects option

I needed node-csv to parse an incoming CSV stream, transform each row and then pipe it onwards as objects. I'm not sure of the best way to do this, but simply adding an option to preserve objects instead of stringifying them worked for me. Is there a better way? Of use to anyone else? If so I can write a test case.

For example, given incoming data like:

```
first_name,last_name
John,Doe
Fred,Bloggs
```

and a desired output of:
```
[
{
first_name:"John",
last_name:"Doe"
},
{
first_name:"Fred",
last_name:"Bloggs"
}
]
```

this would work:
```js
var csv = require('csv');
var fs = require('fs');
var JSONStream = require('JSONStream');

var inFile = fs.createReadStream('./sample.in');
var outFile = fs.createWriteStream('./sample.out');

var csvToObjects = csv()
.from.options({columns:true})
.to.options({preserveObjects:true});

inFile.pipe(csvToObjects).pipe(JSONStream.stringify()).pipe(outFile);
```

In this case I'm just stringifying the stream, but you can imagine having a stream of objects can be useful for writing to a database, etc.