Skip to content

Instantly share code, notes, and snippets.

@uhtred
Created March 23, 2016 18:07
Show Gist options
  • Save uhtred/630258c6fe3965edcc5d to your computer and use it in GitHub Desktop.
Save uhtred/630258c6fe3965edcc5d to your computer and use it in GitHub Desktop.
JS: QueryString to JSON
queryStringToJson: function(querystring) {
var pairs = querystring.split('&');
var result = {};
pairs.forEach(function(pair) {
pair = pair.split('=');
result[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, '%20') || '');
});
return JSON.parse(JSON.stringify(result));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment