JSON, XML, Protobuf and more: how data is written down to travel over a network.
A data format is the way we write data down so it can travel over a network or be saved. Both sides must use the same format.
A program keeps data in memory as objects. A network cannot carry objects. It can only carry bytes. So we must change the object into bytes and back.
{"name":"Asha","age":28}<user><name>Asha</name><age>28</age></user>
name,age Asha,28
The format you choose changes speed, cost, safety and how easy it is to change the system later.
| Format | Where it is common |
|---|---|
| JSON | Public web and mobile APIs, config files, NoSQL documents |
| XML | SOAP, older enterprise systems, RSS feeds, many document formats |
| YAML | Config files: Kubernetes, CI pipelines, OpenAPI files |
| CSV | Spreadsheets, data exports and imports, simple reports |
| Protobuf | gRPC, internal service-to-service calls |
| Avro | Kafka and big data pipelines |
| MessagePack / BSON | Compact JSON-like binary (BSON is used by MongoDB) |
| Format | Looks like | Good at | Weak at |
|---|---|---|---|
| JSON | {"id":1,"tags":["a","b"]} | Simple, everywhere, nests data, easy in JavaScript | No comments, no dates type, repeats keys, no built-in schema |
| XML | <id>1</id> | Strict, has schemas (XSD), attributes, mixed content | Verbose, harder to read and parse |
| YAML | id: 1 | Very readable, has comments, great for config | Indentation mistakes, many surprising rules |
| CSV | id,name | Tiny for flat tables, opens in a spreadsheet | No nesting, no types, quoting rules |
| Format | Idea | Schema? | Common use |
|---|---|---|---|
| Protocol Buffers (Protobuf) | Fields get numbers, not names. Very compact. | Yes (.proto file) | gRPC, internal APIs |
| Avro | Schema is stored with data or in a registry; row-based. | Yes (JSON schema) | Kafka, Hadoop |
| Thrift | Similar idea to Protobuf, with its own RPC | Yes | Some older internal systems |
| MessagePack | βBinary JSONβ: same data model, smaller bytes | No | Caches, fast APIs |
| Parquet / ORC | Column-based files for analytics | Yes | Data warehouses |
Data lives longer than code. Old messages are stored, and old and new servers run at the same time. So a format must allow change.
| Change | Backward compatible? | Notes |
|---|---|---|
| Add an optional field | Yes | Old readers ignore it. New readers use a default for old data. |
| Remove an optional field | Usually | Never reuse its number or name. |
| Rename a field | No in JSON / Avro by name; yes in Protobuf (number stays) | Plan carefully. |
| Change a fieldβs type | Usually No | Make a new field instead. |
{
"name": "Asha",
"age": 28,
"city": "Pune",
"active": true
}JSON, XML and CSV sizes are exact (compact, no extra spaces, UTF-8). The Protobuf size is worked out from its encoding rules (1-byte tags, varints, length prefixes). Real messages may add small extras.
syntax = "proto3";
message User {
string name = 1; // field numbers are what go on the wire
int32 age = 2;
string city = 3;
bool active = 4;
// added later, safe for old readers:
string email = 5;
}HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{"name":"Asha","age":28,"city":"Pune","active":true}Accept header, and the server says what it sent with Content-Type. Common values: application/json, application/xml, text/csv, application/x-protobuf.| Term | Meaning in easy words |
|---|---|
| Serialization | Turning an in-memory object into bytes (text or binary) to send or save |
| Deserialization | Turning the bytes back into an object |
| Schema | A written description of the fields and their types |
| Text format | Human readable, such as JSON, XML, YAML, CSV |
| Binary format | Bytes that are not meant for reading, such as Protobuf and Avro |
| Payload | The data part of a message |
| Backward compatible | New code can read old data |
| Forward compatible | Old code can read new data (by ignoring fields it does not know) |
| Content-Type | An HTTP header that says what format the body is in |
| UTF-8 | The standard way to turn text characters into bytes |
| Compression (gzip) | A separate step that makes any message smaller by squeezing repeated patterns |
| Format | Pros | Cons |
|---|---|---|
| JSON | Readable, simple, universal, great tooling | Larger, no native schema, no binary type |
| XML | Strict, schemas, namespaces, mature | Very verbose, heavy to parse |
| YAML | Most readable, comments | Whitespace traps, slow, not for network APIs |
| CSV | Tiny and simple for tables | Flat only, no types, messy quoting |
| Protobuf | Very small and fast, strong types, safe evolution | Not readable, needs a schema and tools |
| Avro | Compact, schema evolution rules, great for streams | Needs a schema registry in practice, less common in web APIs |
2026-12-01T10:30:00Z).Content-Type and character encoding. Use UTF-8.