What is Serialization and Deserialization in Programming?

Published: (February 22, 2026 at 02:25 AM EST)
6 min read
Source: Dev.to

Source: Dev.to

If you’re learning programming, you’ve probably seen phrases like:

  • “Serialize this object”
  • “Deserialize the JSON”
  • “Convert object to string”

…and it can feel confusing.

Why do we need to convert objects at all?
Why can’t we just use them directly?

Don’t worry – by the end of this article you’ll understand serialization and deserialization in the simplest way possible.

1️⃣ The Confusion (Why This Feels Hard)

You create an object in your program. Everything works perfectly.
Then someone says:

  • “Send this data to the frontend.”
  • “Save this object in a file.”
  • “Store it in a database.”
  • “Send it to another server.”

And suddenly you’re told: “First serialize it.”

Now it feels scary. What does that even mean?

2️⃣ Why Serialization Exists (The Real Problem)

Inside your program, data lives in memory (RAM).

Problems with raw memory

  • Memory disappears when the program stops.
  • You cannot send raw memory to another computer.
  • You cannot store a memory structure directly in a file.
  • Another programming language cannot understand your internal object format.

Computers only understand:

  • Text
  • Raw bytes (0s and 1s)

So developers needed a way to convert objects into something that can be saved or sent.
That solution is called serialization.

When we convert it back, that is called deserialization.

3️⃣ Real‑Life Analogy (Super Simple)

Imagine you build a LEGO car. Inside your room it’s fully assembled.
Now you want to send it to your cousin in another city. You cannot ship it fully assembled, so you:

  1. Break it into pieces.
  2. Put the pieces inside a box.
  3. Send the box.

Your cousin receives the box, opens it, and rebuilds the LEGO car.

  • Breaking and packing → Serialization
  • Rebuilding → Deserialization

That’s it. Nothing magical.

4️⃣ The Simple Explanation (No Complex Words)

  • Serialization = Converting an object into text or bytes so it can be saved or sent.
  • Deserialization = Converting that text or bytes back into the original object.

In short:

Object → Text/Bytes → Object

5️⃣ How Serialization Works (Step‑by‑Step)

Let’s imagine we have this student data in Python:

student = {
    "name": "Rahul",
    "age": 15
}

🔹 Step 1: Serialize

Convert it into JSON (a text format):

{"name": "Rahul", "age": 15}

Now it is just text. This text can:

  • Be saved in a file
  • Be stored in a database
  • Be sent through an API
  • Be shared between different programming languages

🔹 Step 2: Deserialize

When someone receives this text, they convert it back into an object:

student = {"name": "Rahul", "age": 15}

Now it behaves like a normal object again.

6️⃣ Very Small Code Example (Python)

Serialization Example

import json  # Library to work with JSON

student = {
    "name": "Rahul",
    "age": 15
}

# Convert dictionary to JSON string
serialized_data = json.dumps(student)

print(serialized_data)

Output

{"name": "Rahul", "age": 15}

Deserialization Example

# Convert JSON string back to dictionary
original_data = json.loads(serialized_data)

print(original_data["name"])

Output

Rahul

7️⃣ Dry Run (Most Important Part)

Let’s walk through the process slowly.

  1. Create the object

    student = {"name": "Rahul", "age": 15}

    This is a dictionary stored in memory.

  2. Serialize

    serialized_data = json.dumps(student)

    Result:

    serialized_data = '{"name": "Rahul", "age": 15}'

    Important: serialized_data is now a string, not a dictionary.
    Trying to do serialized_data["name"] will raise an error because it’s just text.

  3. Deserialize

    original_data = json.loads(serialized_data)

    Now original_data is a dictionary again, so original_data["name"] works.

Full journey

Object → JSON String → Object

8️⃣ Where Serialization Is Used in the Real World

Serialization is everywhere:

  • 🌐 Front‑end sending data to back‑end
  • 📱 Mobile app calling a server
  • 💾 Saving data in a file
  • 🗄️ Storing objects in a database
  • 🔐 Sending data between microservices
  • 🎮 Saving game progress
  • 📨 Transmitting data over a network

Every time you use an API, serialization happens behind the scenes. When Instagram loads your profile… serialization and deserialization are working silently.

9️⃣ Common Beginner Mistakes

  • Thinking JSON is the same as an object – JSON is text; the object lives in memory.
  • Forgetting that serialization converts an object into a string – you can’t access properties directly on the string.
  • Trying to access JSON like a dictionary without deserializing.
  • Assuming serialization only means JSON – it can also be XML, binary formats, Protocol Buffers, etc.

🔟 Serialization vs. Deserialization (Quick Comparison)

SerializationDeserialization
DirectionObject → Text/BytesText/Bytes → Object
When it happensBefore sending or savingAfter receiving or reading
Where it happensSender sideReceiver side

1️⃣1️⃣ When Should You Use Serialization?

  • Whenever you need to persist data (files, databases, caches).
  • Whenever you need to communicate between processes, services, or machines.
  • When you want to share data across different programming languages or platforms.

In short, anytime data must leave the memory of the current program, you’ll need serialization (and the corresponding deserialization on the other side).

Use Serialization When

  • You want to send data to another system
  • You want to save an object permanently
  • You want different languages to understand your data
  • You are building APIs
  • You are working with databases

If data is moving outside your program, serialization is involved.

1️⃣2️⃣ Quick Revision Summary

  • Serialization = Object → Text/Bytes
  • Deserialization = Text/Bytes → Object
  • Needed to send or save data
  • JSON is the most common format
  • After serialization, data becomes a string
  • Must deserialize before using it as an object
  • Used in APIs, databases, mobile apps, and servers

Now, if someone says:

“Serialize this object before sending it.”

You won’t panic.
You’ll just think:

“Ohhh… we’re packing it into a box.”

And that’s it.

0 views
Back to Blog

Related posts

Read more »

Undefined vs Not Defined

Undefined undefined is a special keyword in JavaScript. It means the variable exists in memory, but no value has been assigned yet. During the creation phase o...