Skip to content

Instantly share code, notes, and snippets.

@mgd020
Created December 11, 2017 13:36
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 mgd020/397aaee5b5fc1aabd0d68bceb5703ded to your computer and use it in GitHub Desktop.
Save mgd020/397aaee5b5fc1aabd0d68bceb5703ded to your computer and use it in GitHub Desktop.
encode json for
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