Opened 11 years ago

Last modified 5 years ago

#12747 assigned defect

Nested object serialization with objectToQuery

Reported by: lyle Owned by: dylan
Priority: high Milestone: 1.15
Component: IO Version: 1.6.0
Keywords: dojo xhr Cc:
Blocked By: Blocking:


Apparently dojo has no ability by default to serialize regular nested objects via dojo.objectToQuery.

Right now doing this:

dojo.objectToQuery({user: {username: 'lyle', password: 'testing'}});

will generate the query:

user=[Object object]

This is useless to everybody. The generally accepted solution is the following:


This is how PHP and Rails expect nested objects, and it's how Zend and Rails build their forms by default. This is also how jQuery serializes nested objects.

This may not be the perfect solution, but you shouldn't get garbage when you put nested objects into objectToQuery.

Also, I noticed that in an older version of node.js this syntax was expected for nested objects, but at some point it has changed to no longer accept it in the way I've outlined. I don't know why that is but I'm plenty curious.

Change History (6)

comment:1 Changed 11 years ago by ben hockey

the problem is that there is no standard, or arguably even a general way to represent deep objects in a querystring. if you were using struts for example then the query for your object should be:


which is different to the example you give but maybe just as intuitive and widespread.

dojo is used to make requests from many different backends and without a standard to follow, its difficult to justify implementing one particular option over another. the best that can be done is to give you tools to build what you need and make it trivial for you to implement your specific option. a couple of years ago i wrote a custom objectToQuery for struts in ~20 lines of code - follow the current implementation of objectToQuery and for each property in the object, check if it's an array or object and then recurse if needed.

comment:2 Changed 11 years ago by lyle

I definitely don't disagree that it should be easy to override this behavior. In fact, I feel it would be easier to override nested objectToQuery serialization behavior if there were a sensible hook implemented and maybe even a default implementation of nested object serialization. I really don't care which one. This just feels broken by default to me.

comment:3 Changed 10 years ago by Thomas Bachem


jQuery's $.param() method does support nested parameters with this syntax, see

The current behaviour (putting stuff like "[Object object]" into the query string) makes no sense at all, so every other solution - if there's a standard or not - would probably be better :).

comment:4 Changed 10 years ago by bill

Component: CoreIO
Owner: set to Bryan Forbes

You can close as wontfix if this is addressed with the new dojo/request code. Or is this not in the IO category?

comment:5 Changed 6 years ago by dylan

Milestone: tbd1.12
Owner: changed from Bryan Forbes to dylan
Status: newassigned

Verified that this is still an issue when using dojo/request. Setting a query on a request like this:

query: {
		keys: {
				foo: "value",
				bar: "another"

will send the URL as: http://someurl?keys=%5Bobject%20Object

comment:6 Changed 5 years ago by dylan

Milestone: 1.131.15

Ticket planning... move current 1.13 tickets out to 1.15 to make it easier to move tickets into the 1.13 milestone.

Note: See TracTickets for help on using tickets.