Skip to content

Instantly share code, notes, and snippets.

@rosscdh
Last active June 23, 2025 16:44
Show Gist options
  • Select an option

  • Save rosscdh/f4f26758b0228f475b132c688f15af2b to your computer and use it in GitHub Desktop.

Select an option

Save rosscdh/f4f26758b0228f475b132c688f15af2b to your computer and use it in GitHub Desktop.
PeeWee JSONField
import peewee as pw
class JSONField(pw.TextField):
"""
Class to "fake" a JSON field with a text field. Not efficient but works nicely
"""
def db_value(self, value):
"""Convert the python value for storage in the database."""
return value if value is None else json.dumps(value)
def python_value(self, value):
"""Convert the database value to a pythonic value."""
return value if value is None else json.loads(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment