Serialization and JSON

Goals

  1. Describe serialization.
  2. Explain how to serialize and deserialize using python and JSON.

Serialization and Deserialization

Serialization is the process of converting a data structure (like a Python object) into a format that can be stored or transmitted, such as a string, file, or stream.

Deserialization is the reverse — converting that format back into a usable data structure.

S:D in Python

Term Function Direction
Serialization json.dumps() Python → JSON string
Deserialization json.loads() JSON string → Python

S:D in Django

If your Django model field is a JSONField, there is no need to manually serialize or deserialize your data structure because Django does this automatically for you.