This happens on a return JSONResponsethat was added in Django 1.7. and is a wrapper around json.dumps. However, an error occurs in this case. I am sure that the data is correct and can be serialized in JSON through the Python shell.
What is the correct way to serialize data in JSON?
from django.http import JsonResponse
from collections import OrderedDict
data = OrderedDict([('doc', '546546545'), ('order', '98745'), ('nothing', '0.0')])
return JsonResponse(data)
Results of this error:
<map object at 0x7fa3435f3048> is not JSON serializable
print(data) gives:
OrderedDict([('doc', '546546545'), ('order', '98745'), ('nothing', '0.0')])
source
share