Wednesday, 28 August 2013

Separators in django.simplejson "missing"

Separators in django.simplejson "missing"

In django I have created a view that returns a json object.
def get_json_for_all_drives(request):
drive_ids = []
for entry in Drive.objects.all():
drive_ids.append(entry.id)
no_of_drives = len(drive_ids)
all_values = []
for drive_id in drive_ids:
drive_values = []
for entry in Drivespace.objects.filter(driveid=drive_id):
drive_values.append([delorean.Delorean(entry.datetime,
timezone="UTC").epoch()*1000,entry.freespace/1024.0/1024.0/1024.0])
all_values.append(drive_values)
data = simplejson.dumps(all_values, separators=(',',','))
return HttpResponse(all_values,content_type = 'application/json;
charset=utf8')
However, there is a thing that bothers me. The result looks like the
following:
[[1,1],[2,2],[3,3]][[a,a],[b,b],[c,]]
As you can see there is no comma between the two lists. Without the comma
I am not able to parse is it in javascript. If I work with a fixed set of
arguments to dump into jason it works, e.g.:
data = simplejson.dumps([myList[0], myList[1]])
Does anyone have an idea on how to solve this?

No comments:

Post a Comment