I've built a Django view for the sake of returning a pure JSON object:
from django.core import serializers
import json
def testjson(request):
all_objects = list(Message.objects.all())
to_json = serializers.serialize('json', all_objects)
return HttpResponse(json.dumps(to_json), mimetype='application/json')
to_json above only ends up looking something like this:
\"employees\": [
{ \"firstName\":\"John\" , \"lastName\":\"Doe\" },
{ \"firstName\":\"Anna\" , \"lastName\":\"Smith\" },
{ \"firstName\":\"Peter\" , \"lastName\":\"Jones\" }
]
This is completely useless with the \
and I can't figure out how to get rid of them.
I've tried this but the \
triggers an escape character:
to_json = to_json.replace('\', '')
How do I change the JSON object to replace the \"
with just "
?