I’m using json.dump() and json.load() to save/read a dictionary of strings to/from disk. The issue is that I can’t have any of the strings in unicode. They seem to be in unicode no matter how I set the parameters to dump/load (including ensure_ascii and encoding).
I’m using json.dump() and json.load() to save/read a dictionary of strings to/from disk. The
Share
If you are just dealing with simple JSON objects, you can use the following:
Here is an example of how it works:
This answer works for a more complex JSON structure, and gives some nice explanation on the
object_hookparameter. There is also another answer there that recursively takes the result of ajson.loads()call and converts all of the Unicode strings to byte strings.