Skip to content

Instantly share code, notes, and snippets.

@kamontat
Created February 18, 2019 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamontat/bfd00a3a3a4f2d64cb01f59af16b73fc to your computer and use it in GitHub Desktop.
Save kamontat/bfd00a3a3a4f2d64cb01f59af16b73fc to your computer and use it in GitHub Desktop.
convert facebook information encode to correct one (only appear when export as JSON)
import json
def parse_obj(obj):
for key in obj:
if type(obj[key]) is str:
obj[key] = obj[key].encode('latin_1').decode('utf-8')
elif type(obj[key]) is list:
obj[key] = list(map(lambda x: x if type(x) != str else x.encode('latin_1').decode('utf-8'), obj[key]))
pass
return obj
filename = ''
# File
with open(filename) as f:
text = json.load(f, object_hook=parse_obj)
print(text)
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment