An object living in your program's memory — a graph of pointers, hash tables, and references — has no meaning outside that process. To send it over a network or save it to disk, you must flatten it into a linear sequence of bytes (serialization) and reconstruct it on the other side (deserialization). The format you choose trades human-readability against speed and size.
Text Formats
JSON is the lingua franca of the web — readable, universally supported, but verbose (keys repeat on every record) and schema-less:
{
"name": "Alice",
"age": 30,
"orders": [
{ "item": "Book", "price": 15.99 },
{ "item": "Pen", "price": 2.50 }
]
}
XML carries the same data far more verbosely, with namespaces and schemas (DTD, XSD); it lingers in enterprise and legacy systems. YAML is the most human-friendly and dominates configuration (Kubernetes, Docker Compose, CI pipelines), but it's indentation-sensitive and full of surprises — most infamously the "Norway problem," where the unquoted country code NO parses as the boolean false.
Binary Formats
When size and speed matter more than readability, binary formats win. Protocol Buffers (Google) is the most popular — you define a schema, and fields are encoded by compact numeric tags instead of repeated names:
message User {
string name = 1;
int32 age = 2;
repeated Order orders = 3;
}
The ecosystem is rich: FlatBuffers and Cap'n Proto offer zero-copy access (read fields without a parse step), Avro shines at schema evolution and pairs with Kafka, MessagePack is "binary JSON" with no schema, and Thrift bundles serialization with an RPC framework.
Analogy: JSON is a letter written in plain English — anyone can read it, but it's wordy. Protobuf is Morse code — compact and fast, but you need the codebook (the schema) to decode it.
Schema Evolution
Real systems change: you add fields, deprecate others, and must keep old and new code interoperating. This is where schemas earn their keep. Add an email field with tag 3, and:
- Old code reading new data simply ignores the unknown field 3. ✓
- New code reading old data sees
emailmissing and uses its default. ✓
The rules that make this safe: never reuse a field number, make new fields optional (give them defaults), and never change a field's type incompatibly.
Analogy: Schema evolution is updating a government form. You can add new optional boxes (the new version), and old submissions are still accepted — the new boxes are just left blank.