Teleporting a Human - Understanding the concept of Serialization and Deserialization in JavaScript

Aryan DhingraAryan Dhingra
4 min read

Hanji , To chaliye Chai Lekr Beth Jayiee Aur Ayie thodi Baatein Serialization Aur Deserialization Ke Upr Krte Hai JavaScript k andr .(Take Your Tea and lets have a small Discussion on Serialization and Deserialization In JavaScript.)

Serialization:

It Is the process of converting a data structure, such as JavaScript object or array into a format that can be easily stored. Basically ,it is the process of converting a data object into a byte Stream. In JavaScript , the most common serialization format is JSON (JavaScript Object Notation). The JSON format is easy for both human and machine to read and write. Serialization is used for converting a data structure into a format that can be stored or sent somewhere, like a text file or over the internet. We use JSON.stringify() to complete the process of Serialization.

const data = { name: "Aryan", age :20};
const jsonString = JSON.stringify(data);
Output : '{"name": Aryan , "age": 20}'

Deserialization :

It is the opposite process of serialization. It converts data in its serialized format into its original data structure, such as JavaScript object or array to make the data usable and accessible in the application. We use JSON.parse() to complete the process of Deserialization.

const jsonString = '{"name": "Aryan", "age" : 20}';

const data = JSON.parse(jsonString);
Output : {name :"Aryan" , age : 20}

Serialization and Deserialization of the Human into a Structured Data

Serialization of the Code or Data : Converting A Human Into Structured a data

Representing a Human as a Data

const human = {
    name : "Aryan",
    age:20,
    height : 5'10 ,
    location : "Haryana",
    hobbies : ["gaming", "coding"]
};

this a JavaScript Object , but we can’t store or send it easily. So using Serialization we are converting the data to a String

const serializedHuman = JSON.stringify(human);
console.log(serializedHuman);

So the output of the above code is:

{"name":"Aryan","age":20,"height":"5'10","location":"Haryana","hobbies":["gaming","coding"]}

And the above data can now get’s saved in a string format and can be sent over the internet and we can also store it in a database.

Deserialization of the code or Data (Recreating the Human)

After the data is reached to the new location or our desired location we can deserialize it back into the object using JSON.parse()

const received Data = JSON.parser(serializedHuman);
console.log(receivedData);

So the Output of the above code is i.e. Deserialization of the data

{
  name: 'Aryan',
  age: 20,
  height: "5'10",
  location: 'Haryana',
  hobbies: [ 'gaming', 'coding' ]
}

Challenges In Teleporting a Human (Using Serialization and Deserialization)

  • Data Loss (Losing Important Information) : When You Forget to include some details about the human when serializing them like if you haven’t filled the age or height or hobbies or some important data about the human. The Solution of this problem is that always make sure that all necessary details should be present while serializing.

  • Data Corruption (Glitched Teleportation) : If the data gets damaged or changed incorrectly then person might be teleport in a broken or distorted way. The solution of this is that use error checking methods before deserializing it.

  • Format Incompatibility (Different languages cant read the data) : Must ensure that data should gets serialized and deserialized in the same language . it means to say that this couldn’t gets happened that you arre serializing the data in json format and another system deserializing it inn XML format. The solution of this is agree on one format before teleporting the data.

  • Security Issues (Hacking of the Data) : Make sure that someone doesn’t intercepts or manipulates the serialized data means someone doesn’t gets changes the data. The solution of this is that Use Encryption to protect serialized data from the hackers.

Thank you for taking the time to read this article on teleporting a human through the lens of serialization and deserialization in JavaScript. I hope this journey into data transformation gave you a new perspective on how objects travel between different environments—just like a teleporter breaking down and reconstructing a person. If you found this insightful, don’t forget to like, share, and let me know your thoughts in the comments. I’d love to hear your views and continue the discussion! Happy coding!

1
Subscribe to my newsletter

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

Written by

Aryan Dhingra
Aryan Dhingra