Created
April 4, 2016 07:17
-
-
Save hyamamoto/c1bd3ca4c3dc6aa49fb24a936afe8b75 to your computer and use it in GitHub Desktop.
Snippet to convert a Json object to a query string for URL.
This file contains hidden or 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 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