Created
December 19, 2022 01:45
-
-
Save PttCodingMan/89bc7640b61d99def06ffd3310bbb5b5 to your computer and use it in GitHub Desktop.
the convert between object and json using Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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