Problem Statement
I have a Django model containing a JSONField among other fields:
class MetaData(models.Model):
main = models.ForeignKey()
name = models.CharField()
dict_field = models.JSONField()
Where dict_field is a "data dump" for any remaining metadata that i don't want to include as a standalone field.
Although it's a data "dump", I still want it to have basic type-validation. How can I validate the inputs of this JSONField such that it only accepts a pre-defined list of keys and their associated types, as follows:
"key1": bool
"key2": int
"key3": Optional[int]
Does django have functionality built in for this type of problem? If not, what other solutions can you recommend? (pydantic, etc.)