Skip to content

Instantly share code, notes, and snippets.

@voronianski
Created July 16, 2012 08:59
Show Gist options
  • Save voronianski/3121670 to your computer and use it in GitHub Desktop.
Save voronianski/3121670 to your computer and use it in GitHub Desktop.
Custom function serializing object to json
/**
* Serializing object function
*/
$.fn.serializeObject = function()
{
var object = {};
var array = this.serializeArray();
$.each(array, function() {
if (object[this.name] !== undefined) {
if (!object[this.name].push) {
object[this.name] = [object[this.name]];
}
object[this.name].push(this.value || '');
} else {
object[this.name] = this.value || '';
}
});
return object;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment