I want to serialize my form data into a JSON object like it's described in the following thread: Convert form data to JavaScript object with jQuery
However besides of single fields which go as they appear in the form I have fields which I want to group into separate objects. For example, I have 2 fields - startDate and endDate. And in JSON object I want to achieve the following structure:
"dates" : {
"startDate" : "03/19/2014",
"endDate" : "03/27/2014"
},
So, I want to get the values for firstDate and endDate, combine them in an object dates and add to the object which contains the values for separate fields.
Can anybody give me a hint on how can this be achieved? Is there a way to define a some kind of JSON "template" and replace the values of properties with the values from the form?
And a more deep example which I'll need to support:
"demographic" : {
"declaredGender" : "any",
"estimatedGender" : "female",
"estimatedGenderConfidence" : 50,
"declaredYearOfBirth" : {
"from" : "1960",
"to" : "1990"
},
"estimatedYearOfBirth" : {
"from" : "1980",
"to" : "1990"
},
"estimatedYearOfBirthConfidence" : 50
},
Thanks.