SQLite extension · MessagePack

MessagePack, native to SQL

It’s like the JSON1 extension. But binary — faster and smaller.

sqlite-msgpack adds functions for creating, querying, and mutating MessagePack BLOBs directly inside SQL. The API mirrors SQLite’s built-in JSON1 functions, so msgpack_extract, msgpack_set, and msgpack_each feel instantly familiar.

JSON 27 bytes
{ "compact" : true , "schema" : 0 }
MessagePack 18 bytes
82 a7 compact c3 a6 schema 00

Same data, 9 fewer bytes (33%) — and on real records the savings compound. Stored as an ordinary SQLite BLOB.

Why sqlite-msgpack

Binary documents, full SQL power

A complete, deterministic, side-effect-free MessagePack toolkit that lives inside your queries.

JSON1-compatible API

Path syntax and function names mirror json_extract, json_set, and json_each. No new mental model to learn.

Smaller & faster

Compact binary encoding with the smallest-format rule. Builds and extractions routinely beat JSON and JSONB.

Schema validation

Validate BLOBs against a JSON-Schema-style contract right in CHECK constraints and triggers.

Copy-on-write

Every mutation returns a new BLOB; originals are never modified. All functions are deterministic.

Six languages, one format

Native Blob libraries for C++, Python, JS/TS, Rust, and Go produce byte-identical output. Blobs round-trip freely.

Full spec compliance

All 36 MessagePack format families, ext types, and the timestamp extension — with hard limits on untrusted blobs.

Quick start

Load it, then query like JSON

Once the extension is loaded, every msgpack_* function is available in every connection.

-- Build a map and extract from it
SELECT msgpack_extract(
  msgpack_object('name', 'Alice', 'age', 30),
  '$.name'
);                                            -- Alice

-- Update a value (returns a new BLOB; original is unchanged)
SELECT msgpack_to_json(
  msgpack_set(msgpack_object('a', 1), '$.b', 2)
);                                            -- {"a":1,"b":2}

-- Convert to and from JSON
SELECT msgpack_to_json(msgpack_from_json('[1,true,"hi"]'));  -- [1,true,"hi"]

-- Aggregate rows into a msgpack array
CREATE TABLE t(v INTEGER);
INSERT INTO t VALUES (1),(2),(3);
SELECT msgpack_to_json(msgpack_group_array(v)) FROM t;       -- [1,2,3]

Read the guide → Browse all functions

Language libraries

The same Blob API, everywhere

Beyond the SQLite extension, the Blob API ships as self-contained, zero-dependency packages. Output is byte-identical across all of them.

Ready to pack some bytes?

Build from source with CMake, load the extension, and start querying binary documents in SQL.