text: from django.http import HttpResponse
  import json
  
  
  def json_response(func):
      """
      A decorator thats takes a view response and turns it
      into json. If a callback is added through GET or POST
      the response is JSONP.
      """
      def decorator(request, *args, **kwargs):
          objects = func(request, *args, **kwargs)
          if isinstance(objects, HttpResponse):
              return objects
          try:
              data = json.dumps(objects)
              if 'callback' in request.GET:
                  # a jsonp response!
                  data = '%s(%s);' % (request.GET['callback'], data)
                  return HttpResponse(data, "text/javascript")
              if 'callback' in request.POST:
                  # a jsonp response!
                  data = '%s(%s);' % (request.POST['callback'], data)
                  return HttpResponse(data, "text/javascript")
          except:
              data = json.dumps(str(objects))
          return HttpResponse(data, "application/json")
      return decorator
  