I'm trying to dump everything from scrapy crawler into json file but äåö changes to something like \u00f6. How do I fix that?
Asked
Active
Viewed 189 times
0
-
FYI `\u00f6` is `ö`. – khelwood May 14 '21 at 13:40
-
@khelwood thanks, that makes sense... – Dastan Taibosunov May 14 '21 at 13:42
1 Answers
0
Use ensure_ascii=False
Ex:
import json
data = {"Hello": "äåö"}
print(json.dumps(data, ensure_ascii=False)) # --> {"Hello": "äåö"}
Note: If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped. If ensure_ascii is false, these characters will be output as-is.

Rakesh
- 81,458
- 17
- 76
- 113
-
In some more detail, with `ensure_ascii` your text file is portable to any system, whereas without it you are opening the door for various character-encoding problems. Any *conformant* JSON processor will know that the encoding is guaranteed to be UTF-8, but homegrown scripts by beginners are more or less likely to crash or corrupt the data. Tomorrow you'll be back and ask us why Excel displays your _ö_ as _ö_. – tripleee May 14 '21 at 14:27