Wednesday, 3 May 2017

How can i write json to file with pretty and with accents in nodejs?

I tried the following test.js:

var fs = require('fs');
var prettyjson = require('prettyjson');
var data = {
    "content": '\ufeffThis is an example with accents : é è à '
};
fs.writeFile('test.txt', JSON.stringify(data),'utf8', function (err) {});

but the output is:

{"content":"This is an example with accents : � � � "}

How can i use ISO-8859-1 to write to the file? May be some how iconv-lite? Thanks for the helps!



via kodaek99

No comments:

Post a Comment