I have a text file which contains this:
....
{"emojiCharts":{"emoji_icon":"\u2697","repost": 3, "doc": 3, "engagement": 1184, "reach": 6734, "impression": 44898}}
{"emojiCharts":{"emoji_icon":"\U0001f924","repost": 11, "doc": 11, "engagement": 83, "reach": 1047, "impression": 6981}}
....
some of the emojis are in \uhhhh
format, some of them in \Uhhhhhhhh
format.
Does exist any way to encode/decode it to display emojis? Because if the file contains ONLY \Uhhhhhhhh
then everything works fine.
TO come to this stage I have modified file this way:
insightData.decode("raw_unicode_escape").encode('utf-16', 'surrogatepass').decode('utf-16').encode("raw_unicode_escape").decode("latin_1")
To display emojis i need to use this:
insightData.decode("raw_unicode_escape").encode('utf-16', 'surrogatepass').decode('utf-16')
BUT it displays an error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2600' in position 30: ordinal not in range(128)
SOLUTION:
with open(OUTPUT, "r") as infileInsight:
insightData = infileInsight.read()\
.decode('raw_unicode_escape')
with open(OUTPUT, "w+") as outfileInsight:
outfileInsight.write(insightData.encode('utf-8'))