If I have the following view:
<form> <input name="foo" value="bar"> <input name="hello" value="world"> <input name="animals[]" value="panda"> <input name="animals[]" value="koala"> <input name="car[make]" value="Honda"> <input name="car[origin]" value="Japan"> </form>
I use not $("form").serialize() :
foo=bar&hello=world&animals%5B%5D=panda&animals%5B%5D=koalacar&%5Bmake%5D=Honda&car%5Borigin%5D=Japan
Instead, I want:
{"foo":"bar", "hello":"world", "animals":["panda", "koala"], "car":{"make":"Honda", "origin":"Japan"}}
As far as I understand, jQuery used this, but they switched the serialize method to return a GET-style query string. Is there an easy way to get the desired result?
EDIT
I updated my original question to include examples of car[make] and car[origin] . It should be assumed that the input data foo[bar][baz] or foo[bar][baz][bof] may also appear on the form.
In addition, digital indexed keys must be stored, such as foo[0]=a , foo[1]=b , foo[4]=c , for example,
{ ... "foo":["a", "b", undefined, undefined, "c"] ... }
maček source share