Skip to content

Instantly share code, notes, and snippets.

@hyamamoto
Created April 4, 2016 07:17
Show Gist options
  • Save hyamamoto/c1bd3ca4c3dc6aa49fb24a936afe8b75 to your computer and use it in GitHub Desktop.
Save hyamamoto/c1bd3ca4c3dc6aa49fb24a936afe8b75 to your computer and use it in GitHub Desktop.
Snippet to convert a Json object to a query string for URL.
function json2querystring(json) {
return Object.keys(json).map(function(k) { return encodeURIComponent(k) + '=' + encodeURIComponent(json[k]) }).join('&');
}
var json = {param_1:'value1', param_2:'value2', param_3:3};
console.log(json2querystring(json));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment