Skip to content

Instantly share code, notes, and snippets.

@tarmann
Last active December 17, 2015 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tarmann/5618580 to your computer and use it in GitHub Desktop.
Save tarmann/5618580 to your computer and use it in GitHub Desktop.
JavaScript: Underscore Serialize JSON
_.mixin({
serialize: function (obj) {
var urlParams = _.map(obj, function (val, key) {
var value = (_.isObject(val)) ? JSON.stringify(val) : String(val);
return String(key) + '=' + value;
});
return urlParams.join('&');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment