Skip to content

Special characters are broken on output #528

Description

@MichaelA59

json2csv - 5.0.5
Node - 10.16.0

Running into an issue where special characters are being outputted incorrectly.

Input string: Postică
Outputted as: Postică

I need my file to be UTF-8 encoded (apparently doing this correctly) but also needs to account for special characters. If I export the file as a TXT file, the issue goes away, but that is not a viable solution for me. I need this exported as a CSV file.

Here's the function I built which uses the package. It accepts a JSON payload of data to compile the report.

function buildCSV(fields, data, file_name, extention = '', folder = 'Feeds') {
  const opts   = { fields };
  const parser = new Parser(opts, {withBOM: true});
  const csv    = parser.parse(data);

  let path = `./../../${extention}${folder}/Dated Backups/${file_name}.csv`;

  fs.writeFile(path, csv, function(err) {
    if (err) {
      throw err;
    }
  });
}

This is being used as a module, not CLI.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions