Skip to main content
2 of 5
added 141 characters in body
user3740387
  • 367
  • 1
  • 4
  • 14

UTF8 encoded characters not displaying properly on NodeJS

When I print the following

console.log('\xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa6\xe0\xa4\xaf followed you') console.log(utf8.decode('\xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa6\xe0\xa4\xaf followed you')) 

the result rightly is

थडथडदय followed you - (i) थडथडदय followed you - (ii) 

When I access a redis list using redis.lrange('notif-'+userId, 0, -1) its first element is displayed as

["\xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa6\xe0\xa4\xaf followed you", "Users", "233", "some_url", 201, "Users"] 

(note that above is a list stored as a string in redis using redis.lpush('notif-'+userId, python-list), its the first item of a redis list)

Since the above can't be put into JSON.parse because of \x, I escape the slash and then revert using

let notificationList = JSON.parse(notificationParent.replace(/\\/g, '\\\\')) notification.text = notificationList[0].replace(/\\\\/g, '\\') 

Now, when I console.log(notification.text) and console.log(utf8.decode(notification.text)), what gets printed is

\xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa6\xe0\xa4\xaf followed you \xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa5\xe0\xa4\xa1\xe0\xa4\xa6\xe0\xa4\xaf followed you 

What should I do to get results similar to (i) and (ii)?

user3740387
  • 367
  • 1
  • 4
  • 14