Skip to content

downstreamFormat - Last in array to contain no comma? #333

@CyrisXD

Description

@CyrisXD

Hi there, trying to read a CSV file and stream its output data to another JSON array file.

          var Converter = require("csvtojson").Converter;

          var csvConverter = new Converter({
            constructResult: false,
            downstreamFormat: "array"
          });

          var readStream = require("fs").createReadStream(req.file.path);

          var writeStream = require("fs").createWriteStream("csvData.json");

          readStream
            .pipe(csvConverter)
            .subscribe((jsonObj, index) => {
              jsonObj.myNewKey = "some value";
            })
            .pipe(writeStream);

But the last JSON added to the array adds an extra comma at the end creating an invalid array/json.

As such:

[
{Name: Bob},
{Name: Sarah},
{Name: James},
]

How could I make sure it doesn't add the comma on the last entry?
Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions