Is there a way to control json serialization in django? Simple code below will return serialized object in json:
co = Collection.objects.all()
c = serializer
That's really easy. Quick example:
from django.http import HttpResponse
from django.utils import simplejson
def simple_view(request):
response = {'string': "test",
'number': 42,
'array': [1, 2, 3],
'js_object': dict(foo="bar")}
return HttpResponse(simplejson.dumps(response),
mimetype="application/json")
This view will return the equivalent of the following JSON:
{"string": "test",
"number": 42,
"array": [1, 2, 3],
"js_object": {foo: "bar"}}
EDIT: And yes, Assaf Lavie is right, your template can spew invalid JSON.