I've a JSONField in model, lets say x. I'm using DRF to save the model instance.
Serializer:-
class ABCSerializer(serializers.ModelSerializer):
class Meta:
model = ABC
fields = ('x', )
def create(self, data):
instance = ABC.objects.create(**data)
instance.x = {'key': 'value'}
instance.save()
When I POST the data, the response returned by creating the object is correctly deserialized, ie
{
'id': 1,
'x': {
'key': 'value'
}
}
However, when I GET the data using the id, it return x as str, ie
{
'id': 1,
'x': "{\"key\": \"value\"}"
}
How can I properly deserialize the data back to json?