Skip to content

Instantly share code, notes, and snippets.

@jgs03177
Created January 23, 2024 10:57
Show Gist options
  • Save jgs03177/aef6eef884b203c7a10b345c62812253 to your computer and use it in GitHub Desktop.
Save jgs03177/aef6eef884b203c7a10b345c62812253 to your computer and use it in GitHub Desktop.
fix dict unicode escape (maybe because of json)
def _decode_unicode_escape_in_dict_(target_dict):
new_dict = {}
for key1, value1 in target_dict.items():
key1 = key1.encode().decode("unicode-escape")
if isinstance(value1, dict):
value1 = _decode_unicode_escape_in_dict_(value1)
elif isinstance(value1, str):
value1 = value1.encode().decode("unicode-escape")
new_dict[key1] = value1
return new_dict
if __name__ == '__main__':
dict1 = {"aaa": "\\uad50\\ud5a5\\uace1", "\\uad50\\ud5a5\\uace1": dict({"ccc": "\\uad50\\ud5a5\\uace1"})}
dict1 = _decode_unicode_escape_in_dict_(dict1)
print(dict1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment