---
title: "Data serialization"
description: "Data serialization is the process of converting in-memory data structures into a format that can be stored on disk or transmitted over a network, and later reconstructed through deserialization."
canonical: "https://motherduck.com/glossary/data-serialization/"
related:
  - title: "Analyze JSON Data Using SQL and DuckDB"
    url: "https://motherduck.com/blog/analyze-json-data-using-sql/"
  - title: "Loading Data Best Practices | MotherDuck Docs"
    url: "https://motherduck.com/docs/key-tasks/loading-data-into-motherduck/considerations-for-loading-data/"
  - title: "DuckLake Architecture Deep Dive: Catalog, Storage, Compute | MotherDuck"
    url: "https://motherduck.com/videos/ducklake-architecture-deep-dive/"
---

# Data serialization

> Data serialization is the process of converting in-memory data structures into a format that can be stored on disk or transmitted over a network, and later reconstructed through deserialization.

## Overview
Programs represent data in memory using structures specific to their runtime — objects, structs, data frames — that can't be written to a file or sent over a network as-is. Serialization converts that in-memory representation into a defined byte or text layout; deserialization reverses the process, reconstructing usable data structures from those bytes.

## Text vs. binary serialization
Text formats like JSON and XML are human-readable and easy to debug, but verbose and slower to parse. Binary formats like Avro, Protobuf, and Parquet are more compact and faster to process, at the cost of not being readable without tooling. The choice usually comes down to whether human readability, interoperability, or raw performance matters most for a given use case.

## Row vs. columnar serialization
Serialization formats also differ in whether they lay out data by row or by column. Row-based formats like Avro and Protobuf serialize whole records together, which suits streaming and message-passing where a full record is produced or consumed at once. Columnar formats like Parquet serialize each column separately, which suits analytical workloads that scan and aggregate specific columns across many records.

## Schema handling
Some formats embed a schema alongside the data (Avro, Parquet), letting any reader interpret the bytes without external information. Others (like Protobuf) rely on schema definitions compiled separately into code, and JSON is typically schemaless, with structure only implied by convention.

## Serialization in DuckDB
DuckDB reads and writes several serialization formats natively as part of everyday SQL, without a separate library:

```sql
-- Read JSON, a schemaless text serialization
SELECT * FROM read_json('events.json');

-- Convert to Parquet, a compact columnar binary serialization
COPY (FROM read_json('events.json')) TO 'events.parquet' (FORMAT parquet);

-- Serialize a row back to JSON text
SELECT to_json(row(id, name)) FROM users;
```