Created
December 11, 2017 13:36
-
-
Save mgd020/397aaee5b5fc1aabd0d68bceb5703ded to your computer and use it in GitHub Desktop.
encode json for
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
function encodeJSONURIComponent(obj) { | |
return btoa(encodeURIComponent(JSON.stringify(obj))).replace('+', '-').replace('/', '_').replace(/=+$/, ''); | |
} | |
function decodeJSONURIComponent(str) { | |
return JSON.parse(decodeURIComponent(atob(str.replace('-', '+').replace('_', '/')))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment