Skip to content

JSONField does not convert to/from string #8024

Discussion options

You must be logged in to vote

I could be wrong, but I don't think the JSONField is intended to return valid JSON strings at all. The documentation only states that the JSONField "validates that the incoming data structure consists of valid JSON primitives".

The current behavior seems to make sense to me because if you had a JSONField in your model, then you are only looking for JSON validation from the serializer. The model field would still expect a Python dict to be passed to it on save. As mentioned in the SO answer you linked, if you had a JSONField in postgres (which is now supported by Django natively with django.db.models.JSONField), then this would be case.

If you are using a backend that doesn't have JSONField

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by tomchristie
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #8011 on June 07, 2021 09:03.