Skip to content

Instantly share code, notes, and snippets.

@kborchers
Created September 20, 2012 15:58
Show Gist options
  • Save kborchers/3756768 to your computer and use it in GitHub Desktop.
Save kborchers/3756768 to your computer and use it in GitHub Desktop.
$.fn.serializeJSON = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return JSON.parse(o);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment