zemirco / json2csv

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

words missing, JSON with special words like '#' #541

Closed yuqisha closed 2 years ago

yuqisha commented 3 years ago

Hi, there are words missing with csv output converted by json2csv. I use the version 5.0.6. Below is my dataset, my code and the result of csv file.

code:

//dataset
const csvData = [ {
    "external_url": "2#",
  },
  {
    "external_url": "1#",
}]

function handleDownLoadCsv(csvData) {
  const fileParse = {
    fields:[{
        label: '落地页链接',
        value: 'external_url',
      }],
    widthBOM:true,
    excelStrings:true
  };
  try {
    const json2csvParser = new Parser(fileParse);
    const csvContent = 'data:text/csv;charset=GBK,\uFEFF' + csv;
    const encodedUri = encodeURI(csvContent);
  } catch (e) {
    console.log(e)
  }
}

csv result: image

The JOSN content after the first '#' are all missing.

knownasilya commented 3 years ago

Can you paste the actual JSON output? Could be an issue with how you're rendering it

juanjoDiaz commented 3 years ago
const { Parser } = require("json2csv")

const csvData = [
  { "external_url": "2#" },
  { "external_url": "1#" },
];

const fileParse = {
  fields:[{
    label: '落地页链接',
    value: 'external_url',
  }],
  widthBOM:true,
  excelStrings:true
};

const json2csvParser = new Parser(fileParse);
const csv = json2csvParser.parse(csvData);
console.log(csv);

results in

"=""落地页链接"""
"=""2#"""
"=""1#"""

which is exactly as expected.

Not sure what are you doing to get that last item lost... 🤔

juanjoDiaz commented 2 years ago

Closing since the issue can't be replicated and there was no response