Skip to content

Instantly share code, notes, and snippets.

@emmettna
Created October 2, 2017 19:41
Show Gist options
  • Save emmettna/b8846c425eb7f5feac23910d3ed68a63 to your computer and use it in GitHub Desktop.
Save emmettna/b8846c425eb7f5feac23910d3ed68a63 to your computer and use it in GitHub Desktop.
Django Python3 UTF-8 Json decoder method
from django.http import JsonResponse
import json
def get_json_data(data):
try:
return json.loads(data.body.decode('utf-8'))
except TypeError:
return JsonResponse({'response': 'Type Incorrect'})
except Exception as e:
return JsonResponse({'response': 'Unexpected Error as follow : '+str(e)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment