Teleporting a Human – Understanding Serialization & Deserialization in JavaScript

Robin RoyRobin Roy
2 min read

Have you ever dreamed of teleporting from one place to another? Like stepping into a machine, pressing a button, and BOOM — you're in another city?

Well, in the world of programming, we have a similar idea called serialization and deserialization — and it’s just as cool! 🧑‍💻✨

🚀 Step 1: What is Serialization?

Let’s say you want to teleport a human to another city.

But we can’t send the whole person through the internet, right?

So we:

  1. Scan and convert the person into structured digital data (like DNA, memories, traits).

  2. Pack this data nicely into a text format like JSON.

🎯 This process is called Serialization — turning a real-world object (like a person) into data that can be sent or stored.

👾 Step 2: What is Deserialization?

Now the person arrives at the destination as data. We need to rebuild them!

So we:

  1. Read the JSON data

  2. Reconstruct the person (name, age, hobbies — everything!)

🎯 This is Deserialization — converting the data back into a usable object.

👨‍💻 A JavaScript Example

Let’s try teleporting a person using JavaScript!

// Step 1: Human (Object)
const person = {
  name: "Aman",
  age: 25,
  hobbies: ["coding", "gaming", "biryani eating"]
};

// Step 2: Serialize (Teleport data)
const serializedData = JSON.stringify(person);
console.log("Sending:", serializedData);

// Step 3: Deserialize (Rebuild person)
const receivedData = JSON.parse(serializedData);
console.log("Reconstructed Human:", receivedData);

🧠 Why Use Serialization?

  • To store objects in files or databases

  • To send data over the internet (like API requests)

  • To share objects between systems

🧪 Bonus: Not Everything Can Be Teleported!

JavaScript can only serialize simple data (strings, numbers, arrays, objects).

But it can’t serialize:

  • Functions

  • Dates (not properly)

  • Circular references (object inside itself)

🏁 Summary (Teleportation Checklist)

StepAction
👨 Human ObjectCreate a person in JS
🔄 SerializationConvert to JSON with JSON.stringify()
📤 TransferSend the data somewhere
🧑‍🔬 DeserializationRebuild with JSON.parse()
⚠️ Be CarefulWatch for data loss or format issues

So the next time someone says “serialize this object”, imagine you’re turning a person into light particles and sending them across the internet like a sci-fi movie! 🛸

0
Subscribe to my newsletter

Read articles from Robin Roy directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Robin Roy
Robin Roy