0

Supposing I have a field in my model that stores raw JSON (so containing double quotes, null, false etc.):

class Activity(models.Model):
    textjson = models.TextField(default="Unassigned")

how do I serialize this model so that the API response will not contain backslashes, the sign of double serialization?

barciewicz
  • 3,511
  • 6
  • 32
  • 72

1 Answers1

1

If you use PostrgeSQL so you can use JSONFIeld to avoid serialization. To convert raw text to JSON use

json.loads(string)

or to get string from json

json.dumps(json)
nick nick
  • 129
  • 3
  • `segment_efforts` is dumped already - it is raw JSON text. The serializer turns it to text again and backslashes appear. And `json.loads` gives Python object, not text. – barciewicz Dec 16 '18 at 20:09
  • loads() returns dict. As it written above. Which serializer adds slashes to text? – nick nick Dec 16 '18 at 20:20