Skip to content

Instantly share code, notes, and snippets.

@PttCodingMan
Created December 19, 2022 01:45
Show Gist options
  • Save PttCodingMan/89bc7640b61d99def06ffd3310bbb5b5 to your computer and use it in GitHub Desktop.
Save PttCodingMan/89bc7640b61d99def06ffd3310bbb5b5 to your computer and use it in GitHub Desktop.
the convert between object and json using Python.
def obj2base64(obj):
# convert object to base64 string using json
return base64.b64encode(json.dumps(obj).encode('utf-8')).decode('utf-8')
def base642obj(s):
# convert base64 string to object using json
return json.loads(base64.b64decode(s).decode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment