Data Interoperation Guide
Objects & Serialization: JSON, XML, and Protobuf
Different computers and programming languages store data in memory in incompatible ways. Serialization is the process of converting an in-memory object into a standardized format (such as JSON, XML, or Protobuf) so it can travel over a network or be saved to disk, and then be reconstructed by another program.
What Is an Object, and Why Serialize?
In programming, an object is a structured collection of related values
grouped under names (called keys or fields). For example, a program
tracking a studio drawing might hold an object in memory with fields for its
title, year, medium, and a list of
colors.
While a program is running, that object lives in the computer's active memory (RAM) in a
layout specific to that language (for example, a Python dict on a Mac or a
C++ struct on a Jetson). A second computer cannot read the first computer's
RAM directly. To share the object across the network:
- Serialize: Flatten the in-memory object into a neutral, agreed-upon sequence of text or bytes.
- Transmit or Save: Send those bytes over Ethernet (or write them to a file).
- Deserialize: Parse the incoming bytes on the receiving machine back into a native in-memory object.
Figure 4: Serialization converts a language-specific object into a neutral intermediate format; deserialization rebuilds it on the receiving system.
JavaScript & Objects
JavaScript is a programming language used to write applications. It runs
natively inside every web browser (powering interactive pages, <canvas>
drawings, SVG manipulation, and creative coding libraries like p5.js) and can
also run on servers or workstations outside the browser (via runtimes such as Node.js or
Deno).
In JavaScript, an object is a collection of named properties written inside
curly braces { ... }. A JavaScript object can hold both data
(strings, numbers, booleans, arrays, or nested objects) and methods (functions
attached to the object that perform actions):
// A live JavaScript object in memory
const artwork = {
title: "Tide Study",
year: 2026,
framed: true,
colors: ["slate", "moss", "ochre"],
describe() {
return `${this.title} (${this.year})`;
}
};
// Accessing a property and calling a method
console.log(artwork.title); // "Tide Study"
console.log(artwork.describe()); // "Tide Study (2026)"
// Serializing the data portion to a JSON string
const text = JSON.stringify(artwork);
Notice the difference between a live JavaScript object and JSON: a live
JavaScript object can include executable functions like describe(), whereas
JSON only keeps the data properties so any language (Python, C++, Rust, Go) can safely read
the values without executing JavaScript code.
1. JSON (JavaScript Object Notation)
JSON is a plain-text serialization format. Despite its name, it is language-independent: Python, JavaScript, C++, Rust, Go, and shell tools all have built-in or standard libraries to serialize to and deserialize from JSON.
JSON represents data using six building blocks:
- Object: Curly braces
{ ... }containing"key": valuepairs. - Array (List): Square brackets
[ ... ]containing an ordered sequence of values. - String: Text inside double quotes (
"Tide Study"). - Number: Integers or decimals (
2026,0.95). - Boolean:
trueorfalse. - Null:
null(an explicit empty value).
Example: Artwork Object Serialized as JSON
{
"title": "Tide Study",
"year": 2026,
"medium": "ink on paper",
"framed": true,
"colors": ["slate", "moss", "ochre"],
"dimensions_cm": {
"width": 30,
"height": 42
}
}
2. XML (Extensible Markup Language)
XML is a plain-text format that represents data as a tree of nested
<tags> with optional attributes. Before JSON became the default for web
APIs, XML was the primary interoperation format for enterprise systems.
XML remains widely used in document formats and visual media. In particular, SVG (Scalable Vector Graphics)—the format used for the diagrams on this site and for vector illustration tools like Inkscape and Illustrator—is an XML dialect.
Example: The Same Artwork Object Serialized as XML
<artwork framed="true">
<title>Tide Study</title>
<year>2026</year>
<medium>ink on paper</medium>
<colors>
<color>slate</color>
<color>moss</color>
<color>ochre</color>
</colors>
<dimensions unit="cm" width="30" height="42" />
</artwork>
Compared to JSON, XML is more verbose (every opening tag has a closing tag), but it supports attributes, namespaces, and mixed text/markup well—which is why HTML and SVG use tag-based syntax.
3. Protocol Buffers (Protobuf)
Protocol Buffers (Protobuf) is a binary serialization format developed by
Google. Instead of sending field names like "dimensions_cm" repeatedly as
text, both the sender and receiver share a schema file (.proto) that assigns
each field a fixed number and data type.
A compiler (protoc) generates native code from the .proto file
for Python, C++, Go, or other languages. On the wire, only the field numbers and compact
binary values are transmitted.
Example: The Same Artwork Object Defined as a Protobuf Schema
syntax = "proto3";
message Dimensions {
int32 width_cm = 1;
int32 height_cm = 2;
}
message Artwork {
string title = 1;
int32 year = 2;
string medium = 3;
bool framed = 4;
repeated string colors = 5;
Dimensions dimensions = 6;
}
Protobuf is not human-readable on the wire, so it is harder to inspect with a simple text viewer than JSON. However, it produces smaller payloads, parses faster, and enforces strict data types at compile time—making it common in high-throughput internal services and gRPC APIs (such as Triton Inference Server).
4. Schemas & Data Definition Languages (DDLs)
A schema is a formal blueprint (or contract) that defines the structure of
data: which fields exist, what data type each field must hold (text, integer, boolean,
list), and which fields are required. Without a schema, one process might send
"year": "2026" (text) when the receiving process expects
"year": 2026 (a number), causing a parsing error.
A Data Definition Language (DDL) is a specialized syntax used to write a schema. Different systems use different DDLs to describe the same underlying data model:
Example A: SQL DDL (Relational Database Schema)
In a relational database (such as PostgreSQL or SQLite), SQL's DDL statements
(CREATE TABLE, ALTER TABLE) define columns, types, and
constraints before any rows are stored:
CREATE TABLE artworks (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
year INTEGER NOT NULL CHECK (year >= 1900),
medium TEXT NOT NULL,
framed BOOLEAN NOT NULL DEFAULT FALSE,
width_cm INTEGER,
height_cm INTEGER
);
Example B: JSON Schema (API & Tool-Calling Validation)
JSON itself does not require a schema, but JSON Schema lets you describe
and validate JSON objects using JSON syntax. In this cluster, vLLM uses JSON
Schemas for guided decoding, constraining Gemma 4 so its tool-calling output
conforms to the expected parameter types:
{
"type": "object",
"required": ["title", "year", "medium"],
"properties": {
"title": { "type": "string" },
"year": { "type": "integer", "minimum": 1900 },
"medium": { "type": "string" },
"framed": { "type": "boolean" },
"colors": {
"type": "array",
"items": { "type": "string" }
}
}
}
.proto file in Section 3 is also a DDL: it defines the schema that
protoc compiles into code. Similarly, XML uses DDLs such as XSD (XML Schema
Definition) or DTD to validate tag hierarchies.
Comparison Summary
| Format | Encoding | Human Readable | Schema | Common Uses |
|---|---|---|---|---|
| JSON | UTF-8 Text | Yes | Optional (JSON Schema) | Web APIs, LiteLLM / vLLM / Ollama requests, Gemma 4 tool calling, config files. |
| XML | UTF-8 Text | Yes (verbose) | Optional (XSD / DTD) | SVG vector graphics, HTML-adjacent documents, legacy enterprise APIs. |
| Protobuf | Compact Binary | No (requires schema) | Required (.proto) |
gRPC microservices, high-throughput ML inference pipelines, internal RPCs. |