Skip to content

jjson

Read top-level fields from JJSON binary values with TOAST slicing

jjson · Read top-level fields from JJSON binary values with TOAST slicing

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102457jjsonjjson0.1.0TYPEC

PostgreSQL · 18

Usage

Sources:

jjson 0.1.0 reads individual top-level fields from the JJSON binary format stored in a bytea value. It combines a C PostgreSQL entry point with a Rust directory parser. The reviewed repository demonstrates PostgreSQL 18; it has no published release or explicit license grant.

Enable and Read

After the matching library and extension files are installed, a superuser can enable the relocatable extension. Preloading and a server restart are not required.

CREATE EXTENSION jjson;
CREATE TABLE documents (id bigint PRIMARY KEY, payload bytea NOT NULL);
ALTER TABLE documents ALTER COLUMN payload SET STORAGE EXTERNAL;

SELECT jjson_get(payload, 'currency') FROM documents WHERE id = 1;

Populate payload with JJSON bytes produced by the repository’s separate Go CLI. Ordinary JSON text encoded as bytes is not JJSON. An application can bind the bytes directly; the upstream test uses pg_read_binary_file() only as a privileged fixture loader.

jjson_get(bytea, text) returns jsonb. A missing field or SQL-null argument returns SQL NULL; a stored JSON null remains 'null'::jsonb. The SQL function is IMMUTABLE STRICT. Keys and stored JSON use UTF-8, with conversion to and from the database encoding.

Storage and Limits

STORAGE EXTERNAL lets large values remain uncompressed so the C code can read TOAST slices for the footer, directory and selected value. It changes the storage policy; it does not convert existing JSON/JSONB documents or repack existing rows automatically.

Malformed footers, directories, JSON or encoding raise errors. There is no SQL update function or index access method in this revision: jjson_set is listed as future work. The CLI’s file update/vacuum operations are separate from PostgreSQL table updates and maintenance. The installed PostgreSQL library is jjson_lookup; the CLI is not an extension-installed binary.

Table reader