# Serialization

> Turning data into text or bytes to save or send. Reading it back builds it again.

**Field:** Software Development  
**Category:** Files & Formats  
**Also known as:** Serialisation, Serialize, Deserialization, Marshalling

## Think of it like

Think of it like packing a toy flat in a box to post it. Your friend opens it and builds it again.

## Definition

Serialization turns data in a program's memory into a form you can save or send. Usually that form is text, like JSON, or compact bytes. The other side reads it back and rebuilds the data. That step is called deserialization. Every API call and every saved game relies on it. Both sides must agree on the format.

## Example

Jack's game saves the player's level and score as JSON. Next time, it reads the file and puts the player back where they were.

## Example code

```javascript
JSON.stringify({ name: "Emma", age: 36 })
// '{"name":"Emma","age":36}'
```

The object in memory becomes one line of text that can be saved or sent.

## Why it matters

Memory is wiped when a program stops. This is how data lasts, and how it moves between programs.

## Common mistake

Reading in data from a stranger with no check. In some formats, bad data can make your app run an attacker's code.

## Three principles

- **Memory to bytes.** Data becomes text or bytes.
- **Both ways.** Reading it back is called deserialization.
- **Agree on a format.** The sender and the reader must match.

## Related terms

- [JavaScript Object Notation (JSON)](https://learn.benibix.com/term/development/json)
- [Protocol Buffers (Protobuf)](https://learn.benibix.com/term/development/protocol-buffers)
- [Extensible Markup Language (XML)](https://learn.benibix.com/term/development/xml)
- [Application Programming Interface (API)](https://learn.benibix.com/term/development/api)
- [Input Validation](https://learn.benibix.com/term/development/input-validation)

## Taught in

- [Serialization and Protobuf](https://learn.benibix.com/learn/development-formats/serialization-and-protobuf): File Formats, 4/11

![On the left, a box called In memory holds name Emma and age 36. An arrow marked serialize leads to two forms in the middle: JSON text of 24 bytes, written out as name Emma and age 36 in curly brackets, and Protobuf bytes of 8 bytes, 0A 04 45 6D 6D 61 10 24. An arrow marked deserialize leads to Another program, which holds the same name and age. A note says a JSON Schema can check the text first.](https://learn.benibix.com/diagrams/dev2-serialization.svg)

---

Source: https://learn.benibix.com/term/development/serialization
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
