Avoid json.load() converting text to emoji

Viewed 23

I have the following json file:

{
"lupa": [
    "\ud83d\udd0e"
]
}

And this code:

import json

with open('prueba.json',encoding='utf-8') as file:
    new_file = json.load(file,strict=False)
    
json.dump(new_file, file, indent=4, ensure_ascii=False)

The output file says:

{'lupa': ['']}

If I change ensure_ascii to True, it keeps the text in the output file. But it also changes accents and opening exclamation marks, and I only want to keep the ascii version for emojis.

What could I do?

0 Answers
Related