I've used JSONfield in my serilizer and as the user in the thread store json as dict points out, DRF with Mysql stores JSONfield as a dict
However I would rather store it as JSON {"tags":{"data":"test"}} instead of the default behavior of storing it as Dict - {'tags': { 'data': 'test'}} - Daniel suggests using over riding the JSONfield as:
class JSONField(serializers.Field):
def to_representation(self, obj):
return json.loads(obj)
......
However the data is still stored as dict. In my serializers.py I've the overridden the JSONField class and then used it as such
class schemaserializer(serializers.ModelSerializer):
js_data=serializers.JSONField()
However it still saves it as as a dict. Expected behavior: Save it as JSON - POST
retrieve it as dict - GET (so that the render can parse it as JSON)
Am currently doing this manually using json dumps and json loads, but looking for a better way.
The reason to do this is because although I have an API there are instances where users read my DB directly and they need the field to be in a JSON.
Django (2.0.1) Python 3.5 djangorestframework (3.7.7)