tags:

views:

809

answers:

1

I am getting a JSON feed from a server and today I convert it to python object and thus to django view. We are now making an update of our site. whereby

  1. the browser client should parse json using jQuery
  2. also we will have a adobe-air app which will consume JSON directly

However I am not so keen on exposing my back-end server directly to browser/adobe client. How best way to go via django? any existing django-app?

regards django-newbie

+2  A: 

You can use certain built-in elements of Django but I've always found that SimpleJSON makes things so much easier.

Why? With straight serialisation, you don't want to show everything. So with the built-in methods, you have to cut a lot out. With SimpleJSON, you built a dict, fill it with only what you want shown and pump it through the SimpleJSON lib. I find inclusion a lot more secure than exclusion when it comes to exposing APIs.

It's also a lot more versatile for consuming data as your client isn't going to be a django site, it's an AIR app with its own ideas about how to format data (even within a spec like JSON there can and probably will be differences).

Oh and remember that there isn't a date type in JSON. (I only mention it because it caused me pain in the past)

Edit: (Thanks Cide) Django ships SimpleJSON in django.utils.simplejson but it might not be there forever. Regardless, you can download it separately from Pypi

Oli
SimpleJSON is actually packaged with django, in `django.utils.simplejson`.
Cide
True but there have been multiple calls to remove it from django. One example: http://www.mail-archive.com/[email protected]/msg19537.html There's no date set for removing it (or confirmation it's staying)
Oli
Ah, I hadn't seen that. Thanks for pointing it out.
Cide