October 21, 2008
JSONField for Django Models
The use of JSON came to mind via the simplejson library. I thought leveraging Python's dict and list data structures would provide ample flexibility will minimizing any parsing of text (at least directly by me). Before I set out to write a JSON field type, I thought I'd give Google a try and sure enough someone (deadwisdom) had beat me to it.
This snippet is really cool in that now I can declare fields of type JSONField() and simple interact with them as python data types however, they get saved to the database as simplejson encoded strings and rehydrated back from strings into their original data structure, leaving you without having to think about how the data will be stored.