title: DJANGO: How to serialize form values into json for storage in a database column
body: <p>I am working on a project and i am required to store information entered into a form to a database column as json. The form does not have a model of its own but all its values will be stored as json into a column of another model. Here is the model:</p>
  
  <pre><code>class Document(models.Model):
      user = models.ForeignKey(User)
      document = models.JSONField(default = {})
      category = models.CharField(max_length=255)
  </code></pre>
  
  <p>Now i am required to store json data from different forms (different <code>category</code>s ) into the column <code>document</code>. Here is one category of such forms:</p>
  
  <pre><code>class InformalLetterForm(forms.Form):
      sender_name = forms.CharField(max_length=45)
      sender_address = forms.CharField(max_length=255)
      date = forms.DateTimeField()
      message_body = forms.CharField()
      receiver_name = forms.CharField(max_length=255)
  </code></pre>
  
  <p>How do i serialize data entered in such a form to a json object to be stored in a database column (i.e the column <code>document</code> above).</p>
  
  <p>i have searched online but i have seen serialization done only for data from model forms.
  Thanks for any help..</p>