Search Shortcut cmd + k | ctrl + k

CBOR (RFC 8949) + MessagePack codec in SQL — decode/validate/canonicalize, tag projection, COSE payload & x5t thumbprint, cross-format transcode

Maintainer(s): alitrack

Compatibility Matrix

This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.

Platform 1.5.5 1.5.6 2.0.0 2.0.1
Linux AMD64
Linux ARM64
macOS AMD64
macOS ARM64
Windows AMD64
Windows ARM64
WebAssembly

Installing and Loading

INSTALL cbor FROM community;
LOAD cbor;

Example

LOAD cbor;

-- Decode: lossless JSON projection.
SELECT cbor_to_json(from_hex('83010203'));      -- [1,2,3]
SELECT cbor_to_json(from_hex('a1616101'));      -- {"a":1}

-- Debug view: keeps tags, byte strings, the null/undefined distinction.
SELECT cbor_diagnostic(from_hex('c11a514b67b0'));  -- 1(1363896240)

-- Validate: total, per-row, never aborts.
SELECT cbor_is_valid(from_hex('830102'));      -- false (truncated)
SELECT cbor_well_formed(from_hex('830102'));   -- {ok: false, error: 'input ended...', kind: 'truncated'}

-- Encode: JSON -> core-deterministic CBOR bytes.
SELECT to_hex(cbor_from_json('[1,2,3]'));      -- 83010203

-- Cross-format: MessagePack -> CBOR, then read back as JSON.
SELECT cbor_to_json(msgpack_to_cbor(from_hex('93010203')));  -- [1,2,3]

About cbor

cbor — CBOR (RFC 8949) + MessagePack in SQL

Decode, validate, canonicalize, tag-project, and transcode binary self-describing data right where you query it — with first-class COSE payload / thumbprint extraction for JWS/CWT/WebAuthn workflows. The lossless JSON projection for CBOR, EDN for the debug view.

The engine (cbor_core/) is a verbatim port of the Query-farm vgi-cbor cbor-core crate (MIT/Apache-2.0) — a pure-Rust structural decoder with no Arrow, no VGI, and no cryptographic verification; only the transport layer was replaced with direct DuckDB C-API vector I/O (via quack-rs).

11 Functions:

Function Signature Returns
cbor_to_json (blob) VARCHAR — canonical JSON (byte strings as base64url)
cbor_diagnostic (blob) VARCHAR — RFC 8949 §8 Extended Diagnostic Notation
cbor_is_valid (blob) BOOLEAN — exactly one well-formed item, no trailing bytes
cbor_well_formed (blob) STRUCT(ok, error, kind) — classified failure taxonomy
cbor_untag (blob, tag UBIGINT) VARCHAR — JSON array of values under a semantic tag
cbor_from_json (json VARCHAR) BLOB — JSON text -> core-deterministic CBOR
cbor_canonical (blob, mode VARCHAR) BLOB — deterministic re-encode (core / ctap2)
cbor_cose_payload (blob) BLOB — COSE inner payload (tagged or unprotected)
cbor_cose_x5t (blob) VARCHAR — COSE x5t thumbprint (lowercase hex)
msgpack_to_json (blob) VARCHAR — MessagePack -> JSON (ext/timestamp handled)
msgpack_to_cbor (blob) BLOB — MessagePack -> CBOR transcode

Decoders are total and bound recursion at a fixed max nesting depth, so a hostile blob fails its own row, never crashes the scan. NULL flows through; malformed input -> NULL (except cbor_canonical with an unknown mode, which is a caller mistake -> clean SQL error).

Added Functions

function_name function_type description comment examples
cbor_canonical scalar NULL NULL  
cbor_cose_payload scalar NULL NULL  
cbor_cose_x5t scalar NULL NULL  
cbor_diagnostic scalar NULL NULL  
cbor_from_json scalar NULL NULL  
cbor_is_valid scalar NULL NULL  
cbor_to_json scalar NULL NULL  
cbor_untag scalar NULL NULL  
cbor_well_formed scalar NULL NULL  
msgpack_to_cbor scalar NULL NULL  
msgpack_to_json scalar NULL NULL  

Overloaded Functions

This extension does not add any function overloads.

Added Types

This extension does not add any types.

Added Settings

name description input_type scope aliases typed_value
temp_directory Set the directory to which temporary files are written. VARCHAR GLOBAL [] post.db.tmp
© 2026 DuckDB Foundation, Amsterdam NL
DuckDB Home Code of Conduct Trademark Use Blog