jquery - Using serializeObject() on a form to create a JSON object with an inner array -


i have form looks little this

<form> <input type='text' name='_id'/> <input type='text' name='name'/> <textarea name='description'/> <input type='text' name='category'/> <input type='checkbox' name='reservable'/> <ol>     <li><input type ='text' name='_id'/><input type='text' name='name'/><input type='text' name='value'/></li>     <li><input type ='text' name='_id'/><input type='text' name='name'/><input type='text' name='value'/></li> </ol> </form> 

i'm trying use serializeobject() method on form , it's working part. problem want elements inside list made array each li element object in array so..

{ _id:'5', name:'bob', description:'tall', categoryid:'human', reservable:'false', attributes: [     {         _id:'3',         name:'hair',         value:'brown'     } ] 

}

what i'm getting looks this

 {  "_id:":"5",  "name:":"bob",  "description:":"tall",  "categoryid":"human",  "name":["hair",""],  "value":["brown",""]  } 

is there way can make attributes array of objects? if tell me why checkbox isn't showing i'd appreciate it.

i doing without testing, don't fail , can push in right direction. try similar this:

html

<form> <input type='text' name='_id' id="the_id"/> <input type='text' name='name' id="the_name"/> <textarea name='description' id="desc"/> <input type='text' name='category id='category'/> <input type='checkbox' name='reservable' id='reservable' /> <ol>     <li><input type ='text' name='_id'/><input type='text' name='name' id='attr_part' /><input type='text' name='value'/></li>     <li><input type ='text' name='_id'/><input type='text' name='name id='attr_color'/><input type='text' name='value'/></li> </ol> </form> 

jquery

// initializes array var person = {};  person.id = $('#the_id').val(); person.name = $('#the_name').val(); person.desc = $('#desc').text(); person.category = $('#category').val(); person.reservable = $('#reservable').val();  // initialize attributes array person.attributes = {};  var attribute = {};  attribute.part = $('#attr_part').val(); attribute.color = $('#attr_color').val();  person.attributes.push(attribute); 

Comments