def return_json_file(request):
 match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
 if match:
  charset = match.group(1)
 else:
  charset = settings.DEFAULT_CHARSET
 obj_dict = json.loads(request.body.decode(charset))
 obj_json = json.dumps(obj_dict, cls=DjangoJSONEncoder, ensure_ascii=False)
 response = HttpResponse(obj_json.encode(charset), status=200, content_type=('application/json; charset=%s' % charset))
 response['Content-Disposition'] = 'attachment; filename=testfile.json'
 return response

def return_json_file ( request ) : match = CONTENT_TYPE_RE . match ( request . META [ 'CONTENT_TYPE' ] ) if match : charset = match . group ( 1 ) else : charset = settings . DEFAULT_CHARSET obj_dict = json . loads ( request . body . decode ( charset ) ) obj_json = json . dumps ( obj_dict , cls = DjangoJSONEncoder , ensure_ascii = False ) response = HttpResponse ( obj_json . encode ( charset ) , status = 200 , content_type = ( 'application/json; charset=%s' % charset ) ) response [ 'Content-Disposition' ] = 'attachment; filename=testfile.json' return response
a view that parses and returns a json string as a file .