django - JSONRenderer won't serialize: b'{"id":"11122211133311"}' is not JSON serializable -


i've problem serializing object using jsonrenderer.

i'm using django-rest-framework , i've serialized object:

  pk = kwargs['pk']   tube = tube.objects.get(id=pk)    serialized_tube = tubeserializer(tube) 

serialized_tube.data looks this:

{'id': '11122211133311'}

unfortunately can't serialize using jsonrenderer, because code

  tube_json = jsonrenderer().render(serialized_tube.data)   return response(tube_json) 

gives following error

b'{"id":"11122211133311"}' not json serializable

whereas

  tube_json = json.dumps(serialized_tube.data)   return response(tube_json) 

works well...

i'm using python3.4.3

the issue not in jsonrenderer() line, in line below return response.

django rest framework provides custom response object automatically rendered whatever accepted renderer was, converting native python structures rendered version (in case, json structures). python dictionary converted json object, , python list converted json array, etc.

right serializing data json string then passing response, expecting re-serialized json. can't serialize string json (you need object or array wrapping it), why seeing error.

the solution not call jsonrenderer ahead of time, , pass serializer data response.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -