can't fix weird characters when saving to .json file from python
Question:
I’m trying to save a text from python but it generates strange characters "u00f1" and I don’t know how to eliminate this
This is the code I’m using:
with open("NoticiasHabboHotel.json", "w") as f:
json.dump(test_versions, f, indent=0, separators=(',', ': '))
This is the text that generates me:
Diseu00f1adores de salas, u00a1os necesitamos!27345
What I want is to convert it into normal letters
I have tried different methods, such as encoding="utf8" and it doesn’t work
Could someone help me, thank you very much!
Answers:
See: https://docs.python.org/3/library/json.html#basic-usage
You need to add ensure_ascii=False
because ñ is a non-ASCII character
with open("NoticiasHabboHotel.json", "w") as f:
json.dump(test_versions, f, indent=0, separators=(',', ': '), ensure_ascii=False)
I’m trying to save a text from python but it generates strange characters "u00f1" and I don’t know how to eliminate this
This is the code I’m using:
with open("NoticiasHabboHotel.json", "w") as f:
json.dump(test_versions, f, indent=0, separators=(',', ': '))
This is the text that generates me:
Diseu00f1adores de salas, u00a1os necesitamos!27345
What I want is to convert it into normal letters
I have tried different methods, such as encoding="utf8" and it doesn’t work
Could someone help me, thank you very much!
See: https://docs.python.org/3/library/json.html#basic-usage
You need to add ensure_ascii=False
because ñ is a non-ASCII character
with open("NoticiasHabboHotel.json", "w") as f:
json.dump(test_versions, f, indent=0, separators=(',', ': '), ensure_ascii=False)