zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.72k stars 362 forks source link

withBom option not working #515

Closed angelo848 closed 3 years ago

angelo848 commented 3 years ago

json2csv version: 5.0.6 node version: 14.15.4 code:

    const options = {
        delimiter: ';',
        withBOM: true,
      };
      const csv = json2csv.parseAsync(dataWithColumnNames, options)
        .then((csvData) => csvData)
        .catch((err) => {
          console.log(err);
          throw err;
        });

example of the dataset: report.zip

datawithColumnNames = {
  Nome_Aluno: "Yuri Meiber de Araujo",
  Instituicao: "IE TESTE",
  Curso: "CURSO TESTE",
  Situacao: "Inadimplente",
  Integracao: "Não possui", // the problem it's here
}

My file output it's on the attachment, basically i'm using the "withBOM" option in the function, but the output still return without the BOM character

juanjoDiaz commented 3 years ago

A quick test shows that the BOM is there:

const json2csv = require("json2csv")

async function test(dataWithColumnNames, options) {
  const csv = await json2csv.parseAsync(dataWithColumnNames, options);

  console.log(csv[0] === '\ufeff');
}

const dataWithColumnNames = {
  Nome_Aluno: "Yuri Meiber de Araujo",
  Instituicao: "IE TESTE",
  Curso: "CURSO TESTE",
  Situacao: "Inadimplente",
  Integracao: "Não possui", // the problem it's here
};

const options = {
    delimiter: ';',
    withBOM: true,
};

test(dataWithColumnNames, options);

Closing. Feel free to reopen if I've missed anything :)