Skip to content

Instantly share code, notes, and snippets.

@mgd020 mgd020/json_uri.js
Created Dec 11, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.