django-rest-framework: How Do I Serialize a Field That Already Contains JSON?

后端 未结 3 2208
孤街浪徒
孤街浪徒 2021-01-05 23:20

I am pretty new to the django-rest-framework, so could use some help.

I have an object with a TextField that is a string containing JSON.

I\'m using django-r

3条回答
  •  甜味超标
    2021-01-06 00:00

    You can simply decode the json into python object:

    json_obj = json.loads(model.json_text)
    

    Once you serialize your object, replace this field with the decoded object:

    data = serializer.data
    data["field"] = json_obj
    return Response(data)
    

提交回复
热议问题