JavaScript csvtojson conversion using Nodejs gives gibberish data csv to json conversion using python,csv to json conversion

I am trying to convert a csv file to json using csvtojson converter in nodejs.My code is as shown below. I get an output of data as shown below. I am not sure why this is happening and how to prevent it.

var Converter  = require("csvtojson").Converter;
var fileStream = fs.createReadStream("input.csv");

var converter = new Converter({constructResult:false});

converter.on("end_parsed", function (jsonObj) {
  var jsonfile = require('jsonfile');
  var file     = 'output.json';
  jsonfile.writeFile(file, jsonObj, function (err) { console.error(err); });});


fileStream.pipe(converter);

{"��P\u0000a\u0000c\u0000k\u0000a\u0000g\u0000e\u0000 \u0000N\u0000a\u0000m\u0000e\u0000":"\u0000c\u0000o\u0000m\u0000.\u0000t\u0000r\u0000i\u0000n\u0000e\u0000t\u0000.\u0000h\u0000r\u0000p\u0000m\u0000o\u0000b\u0000i\u0000l\u0000e\u0000","\u0000A\u0000p\u0000p\u0000 \u0000V\u0000e\u0000r\u0000s\u0000i\u0000o\u0000n\u0000 \u0000C\u0000o\u0000d\u0000e\u0000":"\u00006\u00002\u0000","\u0000R\u0000e\u0000v\u0000i\u0000e\u0000w\u0000e\u0000r\u0000 \u0000L\u0000a\u0000n\u0000g\u0000u\u0000a\u0000g\u0000e\u0000":"\u0000e\u0000n\u0000","\u0000D\u0000e\u0000v\u0000i\u0000c\u0000e\u0000":"\u0000","\u0000R\u0000e\u0000v\u0000i\u0000e\u0000w\u0000 \u0000S\u0000u\u0000b\u0000m\u0000i\u0000t\u0000 \u0000D\u0000a\u0000t\u0000e\u0000 \u0000a\u0000n\u0000d\u0000 \u0000T\u0000i\u0000m\u0000e\u0000":"\u00002\u00000\u00001\u00005\u0000-\u00001\u00002\u0000-\u00002\u00002\u0000T\u00000\u00003\u0000:\u00003\u00002\u0000:\u00003\u00008\u0000Z\u0000","\u0000R\u0000e\u0000v\u0000i\u0000e\u0000w\u0000 \u0000S\u0000u\u0000b\u0000m\u0000i\u0000t\u0000 \u0000M\u0000i\u0000l\u0000l\u0000i\u0000s\u0000 \u0000S\u0000i\u0000n\u0000c\u0000e\u0000 \u0000E\u0000p\u0000o\u0000c\u0000h\u0000":"\u00001\u00004\u00005\u00000\u00007\u00005\u00005\u00001\u00005\u00008\u00002\u00006\u00002\u0000","\u0000R\u0000e\u0000v\u0000i\u0000e\u0000w\u0000 \u0000L\u0000a\u0000s\u0000t\u0000 \u0000U\u0000p\u0000d\u0000a\u0000t\u0000e\u0000 \u0000D\u0000a\u0000t\u0000e\u0000 \u0000a\u0000n\u0000d\u0000 \u0000T\u0000i\u0000m\u0000e\u0000":"\u00002\u00000\u00001\u00005\u0000-\u00001\u00002\u0000-\u00002\u00002\u0000T\u00000\u00003\u0000:\u00003\u00002\u0000:\u00003\u00008\u0000Z\u0000","\u0000R\u0000e\u0000v\u0000i\u0000e\u0000w\u0000 \u0000L\u0000a\u0000s\u0000t\u0000 \u0000U\u0000p\u0000d\u0000a\u0000t\u0000e\u0000 \u0000M\u0000i\u0000l\u0000l\u0000i\u0000s\u0000 \u0000S\u0000i\u0000n\u0000c\u0000e\u0000 \u0000E\u0000p\u0000o\u0000c\u0000h\u0000":"\u00001\u00004\u00005\u00000\u00007\u00005\u00005\u00001\u00005\u00008\u00002\u00006\u00002\u0000","\u0000S\u0000t\u0000a\u0000r\u0000 \u0000R\u0000a\u0000t\u0000i\u0000n\u0000g\u0000":"\u00005\u0000","\u0000R\u0000e\u0000v\u0000i\u0000e\u0000w\u0000 \u0000T\u0000i\u0000t\u0000l\u0000e\u0000":"\u0000","\u0000R\u0000e\u0000v\u0000i\u0000e\u0000w\u0000 \u0000T\u0000e\u0000x\u0000t\u0000":"\u0000","\u0000D\u0000e\u0000v\u0000e\u0000l\u0000o\u0000p\u0000e\u0000r\u0000 \u0000R\u0000e\u0000p\u0000l\u0000y\u0000 \u0000D\u0000a\u0000t\u0000e\u0000 \u0000a\u0000n\u0000d\u0000 \u0000T\u0000i\u0000m\u0000e\u0000":"\u0000","\u0000D\u0000e\u0000v\u0000e\u0000l\u0000o\u0000p\u0000e\u0000r\u0000 \u0000R\u0000e\u0000p\u0000l\u0000y\u0000 \u0000M\u0000i\u0000l\u0000l\u0000i\u0000s\u0000 \u0000S\u0000i\u0000n\u0000c\u0000e\u0000 \u0000E\u0000p\u0000o\u0000c\u0000h\u0000":"\u0000","\u0000D\u0000e\u0000v\u0000e\u0000l\u0000o\u0000p\u0000e\u0000r\u0000 \u0000R\u0000e\u0000p\u0000l\u0000y\u0000 \u0000T\u0000e\u0000x\u0000t\u0000":"\u0000","\u0000R\u0000e\u0000v\u0000i\u0000e\u0000w\u0000 \u0000L\u0000i\u0000n\u0000k\u0000":"\u0000"}, {"��P\u0000a\u0000c\u0000k\u0000a\u0000g\u0000e\u0000 \u0000N\u0000a\u0000m\u0000e\u0000":"\u0000"}

Answer:1

I resolved this issue: It was an encoding issue: correct code was "utf16 "

   var csvEncoding = { encoding: 'utf16le' }; 
    var csvString = fs.readFileSync(csvfile, csvEncoding).toString(); 
    converter.fromString(csvString, function(err,result){ 
    //your code here console.log(err); 
    console.log(result); 

});
Answer:2

I had a very similar issue to OP but was using csv-parse with a file coming out of S3.

Thanks to OP I got on the right path with an encoding issue, I was able to resolve my issue by using utf16le in my stream coupled with iconv-lite like so:

s3
  .getObject(getObjectParams)
  .createReadStream()
  .on('end', () => cb(null))
  .pipe(iconv.decodeStream('utf16le'))
  .pipe(parse({ delimiter: '\t', columns: true }))
  .pipe(transformer);

Hopefully this helps others in the same boat!

Answer:3

I am new to code-igniter. In my View I added this code to enable google login in my website. <html lang="en"> <head> <meta name="google-signin-scope" content="profile email"> <...

I am new to code-igniter. In my View I added this code to enable google login in my website. <html lang="en"> <head> <meta name="google-signin-scope" content="profile email"> <...

  1. send data from javascript to python
  2. send data from arduino to raspberry pi
  3. send data from child to parent react
  4. send data from flask to html
  5. send data from activity to fragment
  6. send data from android to iphone
  7. send data from javascript to python flask
  8. send data from react to node
  9. send data from python to html
  10. send data from one arduino to another
  11. send data from s3 to kinesis
  12. send data from arduino to processing
  13. send data from matlab to arduino
  14. send data from server to client
  15. send data from raspberry pi to pc
  16. send data from child to parent angular
  17. send data from python to arduino
  18. send data from iframe to parent
  19. send data from javascript to php
  20. send data from react to express

what is the difference between bootstrap.min.css and bootstrap.min.js ? Why bootstrap.min.js need to be included? <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/...

what is the difference between bootstrap.min.css and bootstrap.min.js ? Why bootstrap.min.js need to be included? <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/...

  1. what difference between bourbon and whiskey
  2. what difference between vegan and vegetarian
  3. what difference between psoriasis and eczema
  4. what difference between flu a and b
  5. what difference between ipad and ipad air
  6. what difference between republic and democracy
  7. what difference between inc and llc
  8. what difference between chromebook and laptop
  9. what difference between md and do
  10. what difference between virus and bacteria
  11. what difference between w2 and w4
  12. what difference between perfume and eau de toilette
  13. what difference between cold and flu
  14. what difference between catholic and christian
  15. what difference between diabetes 1 and 2
  16. what difference between california king and king
  17. what difference between macbook air and pro
  18. what difference between airpod 1 and 2
  19. what difference between medicare and medicaid
  20. what difference between bipolar 1 and 2

let me description the problem first. i have nav-tab and 3 tab-panes. first portfolio, second recommendation and third statistic. in tab-panes recommendation i want to put a slick.js but when i run, ...

let me description the problem first. i have nav-tab and 3 tab-panes. first portfolio, second recommendation and third statistic. in tab-panes recommendation i want to put a slick.js but when i run, ...

  1. slick inside bootstrap tab
  2. slick slider inside bootstrap tab
  3. slick slider inside bootstrap modal
  4. slick slider inside bootstrap tab not working

I was reading this example on Promise. I realized that Error constructor is not called with new operator. Why does it work, then?

I was reading this example on Promise. I realized that Error constructor is not called with new operator. Why does it work, then?