macek / jquery-serialize-object

Converts HTML form into JavaScript object
Other
1.11k stars 352 forks source link

Complex fields #90

Closed tomasbjerre closed 8 years ago

tomasbjerre commented 8 years ago

Is it possible to convert this kind of fields (or something similar):

<input type="headers[].name" value="n1">
<input type="headers[].value" value="v1">

<input type="headers[].name" value="n2">
<input type="headers[].value" value="v2">

To:

...
"headers": [
 { "name": "n1", "value": "v1" },
 { "name": "n2", "value": "v2" }
]
...

?

tomasbjerre commented 8 years ago
<input name="animals[][name]" value="d">
<input name="animals[][breed]" value="e">
macek commented 8 years ago

This will create the object you're looking for

<input type="headers[0][name]" value="n1">
<input type="headers[0][value]" value="v1">

<input type="headers[1][name]" value="n2">
<input type="headers[1][value]" value="v2">