I want to pass a json object containing nested objects from my client to my server.
on the client side, my data structure is as follows:
var response = {};
response['screening'] = '1';
response['assistance'] = 'wheelchair access';
response['guests'] = {};
response['guests']['1'] = {}
response['guests']['1']['first'] = 'John'
response['guests']['1']['last'] = 'Smith'
response['guests']['2'] = {}
response['guests']['2']['first'] = 'Dave'
response['guests']['2']['last'] = 'Smith'
and my ajax call is as follows:
$.ajax({
type: "POST",
url: window.location.pathname,
data: response
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
after posting this data on my server, which starts using python flags, I use the request.form object to check what was sent by the client. I would like the data to be structured the same way, however this is the result on the server:
ImmutableMultiDict([('guests[1][first]', u'John'), ('screening', u'2'), ('guests[2][last]', u'Smith'), ('guests[2][first]', u'Dave'), ('assistance', u'wheelchair access'), ('guests[1][last]', u'Smith')])
as you can see, the response object ['guest'] was flattened, and all its children, for example:
'guests [2] [first]
... are just strings, not elements of the parent response ['guests'].
?
!