I would like to propose a small enhancement to the JSONResponder. It should
take an extra
parameter, let's call it "root_name", which would be the name of the top-level
key pointing to
the array of data normally returned JSONResponder.
The reason for this addition is that many JavaScript libraries, Yahoo's YUI
being one of them, have
great features for abstracting the processing of returned JSON data but they
usually require that
there be a top-level key-value pair where the value is the usual JSON array
containing the data.
The JSON serializer built-in to Django simply outputs an array which
corresponds to a QuerySet.
This in itself is not an issue because I could build a view which then adds the
extra level to the
returned data structure but when using RESTful APIs we usually don't have
immediate access to
the serializer. Therefore it makes sense to be able to pass an extra option to
JSONResponder
which can then internally build the appropriate structure for us.
For example, Django's built-in JSON serializer will produce this:
[{a: 1, b: 2, c: 3}, {a: 23, b: 43, c: 69}]
But YUI requires an extra level above that, as follows:
{results: [{a: 1, b: 2, c: 3}, {a: 23, b: 43, c: 69}]}
The top-level key does not have to be called "results". It can be any legal
word.
See the attached diff between rev75 and my local repository for the proposed
changes.
cheers,
-tomek
Original issue reported on code.google.com by tomek.pi...@gmail.com on 12 Nov 2007 at 9:29
Original issue reported on code.google.com by
tomek.pi...@gmail.com
on 12 Nov 2007 at 9:29Attachments: