python - Django - reformating the serialized json output -
i pretty new django wanted know best , easiest way reformat serliazed data this:
[ { "pk": 1, "model": "user", "fields": { "name": "john", "last_name": "smith", "acive": true, } } ]
to this:(with data in there)
{"data":[ { "pk": 1, "model": "user", "fields": { "name": "john", "last_name": "smith", "acive": true, } } ]}
this view.py:
def rfc_log_json(request): result = serializers.serialize('json',myuser.objects.all(),) return httpresponse(result, content_type="application/json")
thank you!
try
import simplejson django.core import serializers data = serializers.serialize("json", myuser.objects.all()) user={} user['data']=data simplejson.dumps(user)
Comments
Post a Comment