Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra space character is added when using withBOM: true #190

Closed
daniel-zahariev opened this issue Jul 26, 2017 · 6 comments
Closed

Extra space character is added when using withBOM: true #190

daniel-zahariev opened this issue Jul 26, 2017 · 6 comments

Comments

@daniel-zahariev
Copy link
Contributor

When adding BOM to the CSV output there's an extra space character. This makes Excel show the first cell with quotes.

Code sample

var json2csv = require('json2csv');
var fs = require('fs');
var fields = ['car', 'price', 'color'];
var myCars = [
  {
    "car": "Audi",
    "price": 40000,
    "color": "blue"
  }, {
    "car": "BMW",
    "price": 35000,
    "color": "black"
  }, {
    "car": "Porsche",
    "price": 60000,
    "color": "green"
  }
];
var csv = json2csv({ data: myCars, fields: fields, withBOM: true });

fs.writeFile('file.csv', csv, function(err) {
  if (err) throw err;
  console.log('file saved');
});

CSV output

 "car","price","color"
"Audi",40000,"blue"
"BMW",35000,"black"
"Porsche",60000,"green"
@patresk
Copy link

patresk commented Jul 28, 2017

+1

@knownasilya
Copy link
Collaborator

Would the fix be as simple as removing the space on that line? Or would that break the BOM?

@daniel-zahariev
Copy link
Contributor Author

@knownasilya removing the space won't break the BOM and it's as simple as just deleting it from this string.

@knownasilya
Copy link
Collaborator

I guess the question is, why was it not caught in the test, https://github.com/zemirco/json2csv/blob/master/test/index.js#L720

Feel free to submit a PR with modified test

@juanjoDiaz
Copy link
Collaborator

Any reason why this is still open?

@knownasilya
Copy link
Collaborator

Good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants