I want to create a json on a html form:
<form enctype='application/json'>
<input name='pet[0][species]' value='Dahut'>
<input name='pet[0][name]' value='Hypatia'>
<input name='pet[1][species]' value='Felis Stultus'>
<input name='pet[1][name]' value='Billie'>
</form>
From the html above, I expect to get the following json:
// produces
{
"pet": [
{
"species": "Dahut"
, "name": "Hypatia"
}
, {
"species": "Felis Stultus"
, "name": "Billie"
}
]
}
Without the need of the following code:
function serializeForm()
{
var jsonData = $('form').serializeArray();
var jsonString = JSON.stringify(jsonData);
$('#result').html(jsonString);
}
But, unfortunately, I'm getting the following json:
[{"name":"pet[0][species]","value":"Dahut"},{"name":"pet[0][name]","value":"Hypatia"},{"name":"pet[1][species]","value":"Felis Stultus"},{"name":"pet[1][name]","value":"Billie"}]