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

German Letters not being Encoded/Decoded properly #424

Open
shaunstone0 opened this issue Apr 29, 2021 · 4 comments
Open

German Letters not being Encoded/Decoded properly #424

shaunstone0 opened this issue Apr 29, 2021 · 4 comments

Comments

@shaunstone0
Copy link

When using the package, I have attempted to take a csv files that contains german umlauts (ä, ü) and they are coming out in the json file as T�rkei�

The correct encoding should be UTF-8, however, the package somehow messes up the words.

Or, perhaps I am doing it wrong:

csvtojson({
    headers: ['label','value','poop'], 
    colParser: {
            'label':function(item){
                    return item.toLowerCase();
            },
           'poop': "omit" 
    }}).fromFile(filePath).subscribe((object, err) => {
        object.default = 'false'
        JSON.stringify(object, ["value", "label", "default"])
        
        
    }).then((object) => {
        console.log(object);
        fs.writeFileSync('nation.json', JSON.stringify(object,null, 4), 'utf-8')
    })
@shaunstone0
Copy link
Author

This can be closed. Its Because of Excel removing the BOM when saving the file as a .CSV. You need to make sure to save the file as CSV UTF-8.

@jfoclpf
Copy link

jfoclpf commented Jan 9, 2022

I would not close this issue because I am facing the same problem. The fromFile method should support other encodings than UTF-8 IMHO.

Do you agree @Keyang ?

@jfoclpf
Copy link

jfoclpf commented Jan 9, 2022

I got it :)

const fs = require('fs')
const csv = require('csvtojson')

csv()
  .fromStream(fs.createReadStream('/path/to/file', { encoding: 'latin1' }))
  .subscribe((json) => {
    console.log(json)
  },
  (err) => {
    throw err
  },
  () => {
    console.log('success')
  })

this is indeed a great package :)

@jfoclpf
Copy link

jfoclpf commented Mar 21, 2022

@shaunstone0 did it work the solution?

Would you please close the issue?

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

No branches or pull requests

2 participants