pg_jsonschema

pg_jsonschema

pg_jsonschema : PostgreSQL extension providing JSON Schema validation

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2760
pg_jsonschema
pg_jsonschema
0.3.4
FEAT
Apache-2.0
Rust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
----d--
No
No
No
Yes
no
no
Relationships
See Also
pg_graphql
jsquery
plv8
jsonb_plperl
http
pg_net
pg_summarize
pg_tiktoken

manual update from 0.16.0 by Vonng

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
0.3.4
18
17
16
15
14
pg_jsonschema-
RPM
PIGSTY
0.3.4
18
17
16
15
14
pg_jsonschema_$v-
DEB
PIGSTY
0.3.4
18
17
16
15
14
postgresql-$v-pg-jsonschema-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
el8.aarch64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
el9.x86_64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
el9.aarch64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
el10.x86_64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
el10.aarch64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
d12.x86_64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
d12.aarch64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
d13.x86_64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
d13.aarch64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
u22.x86_64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
u22.aarch64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
u24.x86_64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
u24.aarch64
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PIGSTY 0.3.4
PackageVersionOSORGSIZEFile URL
pg_jsonschema_180.3.4el8.x86_64pigsty1.4 MiBpg_jsonschema_18-0.3.4-1PIGSTY.el8.x86_64.rpm
pg_jsonschema_180.3.4el8.aarch64pigsty1.2 MiBpg_jsonschema_18-0.3.4-1PIGSTY.el8.aarch64.rpm
pg_jsonschema_180.3.4el9.x86_64pigsty1.4 MiBpg_jsonschema_18-0.3.4-1PIGSTY.el9.x86_64.rpm
pg_jsonschema_180.3.4el9.aarch64pigsty1.2 MiBpg_jsonschema_18-0.3.4-1PIGSTY.el9.aarch64.rpm
pg_jsonschema_180.3.4el10.x86_64pigsty1.4 MiBpg_jsonschema_18-0.3.4-1PIGSTY.el10.x86_64.rpm
pg_jsonschema_180.3.4el10.aarch64pigsty1.2 MiBpg_jsonschema_18-0.3.4-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-jsonschema0.3.4d12.x86_64pigsty1.1 MiBpostgresql-18-pg-jsonschema_0.3.4-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-jsonschema0.3.4d12.aarch64pigsty936.8 KiBpostgresql-18-pg-jsonschema_0.3.4-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-jsonschema0.3.4d13.x86_64pigsty1.1 MiBpostgresql-18-pg-jsonschema_0.3.4-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-jsonschema0.3.4d13.aarch64pigsty938.3 KiBpostgresql-18-pg-jsonschema_0.3.4-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-jsonschema0.3.4u22.x86_64pigsty1.3 MiBpostgresql-18-pg-jsonschema_0.3.4-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-jsonschema0.3.4u22.aarch64pigsty1.1 MiBpostgresql-18-pg-jsonschema_0.3.4-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-jsonschema0.3.4u24.x86_64pigsty1.3 MiBpostgresql-18-pg-jsonschema_0.3.4-1PIGSTY~noble_amd64.deb
postgresql-18-pg-jsonschema0.3.4u24.aarch64pigsty1.1 MiBpostgresql-18-pg-jsonschema_0.3.4-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_jsonschema_170.3.4el8.x86_64pigsty1.4 MiBpg_jsonschema_17-0.3.4-1PIGSTY.el8.x86_64.rpm
pg_jsonschema_170.3.4el8.aarch64pigsty1.2 MiBpg_jsonschema_17-0.3.4-1PIGSTY.el8.aarch64.rpm
pg_jsonschema_170.3.4el9.x86_64pigsty1.4 MiBpg_jsonschema_17-0.3.4-1PIGSTY.el9.x86_64.rpm
pg_jsonschema_170.3.4el9.aarch64pigsty1.2 MiBpg_jsonschema_17-0.3.4-1PIGSTY.el9.aarch64.rpm
pg_jsonschema_170.3.4el10.x86_64pigsty1.4 MiBpg_jsonschema_17-0.3.4-1PIGSTY.el10.x86_64.rpm
pg_jsonschema_170.3.4el10.aarch64pigsty1.2 MiBpg_jsonschema_17-0.3.4-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-jsonschema0.3.4d12.x86_64pigsty1.1 MiBpostgresql-17-pg-jsonschema_0.3.4-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-jsonschema0.3.4d12.aarch64pigsty937.0 KiBpostgresql-17-pg-jsonschema_0.3.4-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-jsonschema0.3.4d13.x86_64pigsty1.1 MiBpostgresql-17-pg-jsonschema_0.3.4-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-jsonschema0.3.4d13.aarch64pigsty938.1 KiBpostgresql-17-pg-jsonschema_0.3.4-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-jsonschema0.3.4u22.x86_64pigsty1.3 MiBpostgresql-17-pg-jsonschema_0.3.4-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-jsonschema0.3.4u22.aarch64pigsty1.1 MiBpostgresql-17-pg-jsonschema_0.3.4-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-jsonschema0.3.4u24.x86_64pigsty1.3 MiBpostgresql-17-pg-jsonschema_0.3.4-1PIGSTY~noble_amd64.deb
postgresql-17-pg-jsonschema0.3.4u24.aarch64pigsty1.1 MiBpostgresql-17-pg-jsonschema_0.3.4-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_jsonschema_160.3.4el8.x86_64pigsty1.4 MiBpg_jsonschema_16-0.3.4-1PIGSTY.el8.x86_64.rpm
pg_jsonschema_160.3.4el8.aarch64pigsty1.2 MiBpg_jsonschema_16-0.3.4-1PIGSTY.el8.aarch64.rpm
pg_jsonschema_160.3.4el9.x86_64pigsty1.4 MiBpg_jsonschema_16-0.3.4-1PIGSTY.el9.x86_64.rpm
pg_jsonschema_160.3.4el9.aarch64pigsty1.2 MiBpg_jsonschema_16-0.3.4-1PIGSTY.el9.aarch64.rpm
pg_jsonschema_160.3.4el10.x86_64pigsty1.4 MiBpg_jsonschema_16-0.3.4-1PIGSTY.el10.x86_64.rpm
pg_jsonschema_160.3.4el10.aarch64pigsty1.2 MiBpg_jsonschema_16-0.3.4-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-jsonschema0.3.4d12.x86_64pigsty1.1 MiBpostgresql-16-pg-jsonschema_0.3.4-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-jsonschema0.3.4d12.aarch64pigsty937.2 KiBpostgresql-16-pg-jsonschema_0.3.4-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-jsonschema0.3.4d13.x86_64pigsty1.1 MiBpostgresql-16-pg-jsonschema_0.3.4-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-jsonschema0.3.4d13.aarch64pigsty937.8 KiBpostgresql-16-pg-jsonschema_0.3.4-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-jsonschema0.3.4u22.x86_64pigsty1.3 MiBpostgresql-16-pg-jsonschema_0.3.4-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-jsonschema0.3.4u22.aarch64pigsty1.1 MiBpostgresql-16-pg-jsonschema_0.3.4-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-jsonschema0.3.4u24.x86_64pigsty1.3 MiBpostgresql-16-pg-jsonschema_0.3.4-1PIGSTY~noble_amd64.deb
postgresql-16-pg-jsonschema0.3.4u24.aarch64pigsty1.1 MiBpostgresql-16-pg-jsonschema_0.3.4-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_jsonschema_150.3.4el8.x86_64pigsty1.4 MiBpg_jsonschema_15-0.3.4-1PIGSTY.el8.x86_64.rpm
pg_jsonschema_150.3.4el8.aarch64pigsty1.2 MiBpg_jsonschema_15-0.3.4-1PIGSTY.el8.aarch64.rpm
pg_jsonschema_150.3.4el9.x86_64pigsty1.4 MiBpg_jsonschema_15-0.3.4-1PIGSTY.el9.x86_64.rpm
pg_jsonschema_150.3.4el9.aarch64pigsty1.2 MiBpg_jsonschema_15-0.3.4-1PIGSTY.el9.aarch64.rpm
pg_jsonschema_150.3.4el10.x86_64pigsty1.4 MiBpg_jsonschema_15-0.3.4-1PIGSTY.el10.x86_64.rpm
pg_jsonschema_150.3.4el10.aarch64pigsty1.2 MiBpg_jsonschema_15-0.3.4-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-jsonschema0.3.4d12.x86_64pigsty1.1 MiBpostgresql-15-pg-jsonschema_0.3.4-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-jsonschema0.3.4d12.aarch64pigsty936.9 KiBpostgresql-15-pg-jsonschema_0.3.4-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-jsonschema0.3.4d13.x86_64pigsty1.1 MiBpostgresql-15-pg-jsonschema_0.3.4-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-jsonschema0.3.4d13.aarch64pigsty937.8 KiBpostgresql-15-pg-jsonschema_0.3.4-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-jsonschema0.3.4u22.x86_64pigsty1.3 MiBpostgresql-15-pg-jsonschema_0.3.4-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-jsonschema0.3.4u22.aarch64pigsty1.1 MiBpostgresql-15-pg-jsonschema_0.3.4-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-jsonschema0.3.4u24.x86_64pigsty1.3 MiBpostgresql-15-pg-jsonschema_0.3.4-1PIGSTY~noble_amd64.deb
postgresql-15-pg-jsonschema0.3.4u24.aarch64pigsty1.1 MiBpostgresql-15-pg-jsonschema_0.3.4-1PIGSTY~noble_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_jsonschema_140.3.4el8.x86_64pigsty1.4 MiBpg_jsonschema_14-0.3.4-1PIGSTY.el8.x86_64.rpm
pg_jsonschema_140.3.4el8.aarch64pigsty1.2 MiBpg_jsonschema_14-0.3.4-1PIGSTY.el8.aarch64.rpm
pg_jsonschema_140.3.4el9.x86_64pigsty1.4 MiBpg_jsonschema_14-0.3.4-1PIGSTY.el9.x86_64.rpm
pg_jsonschema_140.3.4el9.aarch64pigsty1.2 MiBpg_jsonschema_14-0.3.4-1PIGSTY.el9.aarch64.rpm
pg_jsonschema_140.3.4el10.x86_64pigsty1.4 MiBpg_jsonschema_14-0.3.4-1PIGSTY.el10.x86_64.rpm
pg_jsonschema_140.3.4el10.aarch64pigsty1.2 MiBpg_jsonschema_14-0.3.4-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-jsonschema0.3.4d12.x86_64pigsty1.1 MiBpostgresql-14-pg-jsonschema_0.3.4-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-jsonschema0.3.4d12.aarch64pigsty937.2 KiBpostgresql-14-pg-jsonschema_0.3.4-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-jsonschema0.3.4d13.x86_64pigsty1.1 MiBpostgresql-14-pg-jsonschema_0.3.4-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-jsonschema0.3.4d13.aarch64pigsty938.3 KiBpostgresql-14-pg-jsonschema_0.3.4-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-jsonschema0.3.4u22.x86_64pigsty1.3 MiBpostgresql-14-pg-jsonschema_0.3.4-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-jsonschema0.3.4u22.aarch64pigsty1.1 MiBpostgresql-14-pg-jsonschema_0.3.4-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-jsonschema0.3.4u24.x86_64pigsty1.3 MiBpostgresql-14-pg-jsonschema_0.3.4-1PIGSTY~noble_amd64.deb
postgresql-14-pg-jsonschema0.3.4u24.aarch64pigsty1.1 MiBpostgresql-14-pg-jsonschema_0.3.4-1PIGSTY~noble_arm64.deb

Source

pig build pkg pg_jsonschema;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_jsonschema;		# install via package name, for the active PG version

pig install pg_jsonschema -v 18;   # install for PG 18
pig install pg_jsonschema -v 17;   # install for PG 17
pig install pg_jsonschema -v 16;   # install for PG 16
pig install pg_jsonschema -v 15;   # install for PG 15
pig install pg_jsonschema -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_jsonschema;

Usage

pg_jsonschema: PostgreSQL extension providing JSON Schema validation

pg_jsonschema adds JSON Schema validation functions to PostgreSQL, enabling schema enforcement on JSON/JSONB columns via check constraints.

Functions

FunctionDescription
json_matches_schema(schema json, instance json)Validate a JSON instance against a schema, returns boolean
jsonb_matches_schema(schema json, instance jsonb)Validate a JSONB instance against a schema, returns boolean
jsonschema_is_valid(schema json)Check whether a JSON schema itself is valid
jsonschema_validation_errors(schema json, instance json)Return an array of validation error messages

Table Constraints

Use check constraints to enforce document structure:

CREATE TABLE customer (
    id serial PRIMARY KEY,
    metadata json,
    CHECK (
        json_matches_schema(
            '{
                "type": "object",
                "properties": {
                    "tags": {
                        "type": "array",
                        "items": {
                            "type": "string",
                            "maxLength": 16
                        }
                    }
                }
            }',
            metadata
        )
    )
);

-- Valid insert (passes check constraint)
INSERT INTO customer(metadata) VALUES ('{"tags": ["vip", "darkmode-ui"]}');

-- Invalid insert (rejected by check constraint)
INSERT INTO customer(metadata) VALUES ('{"tags": [1, 3]}');
-- ERROR: new row violates check constraint

Error Inspection

Retrieve detailed validation errors:

SELECT jsonschema_validation_errors('{"maxLength": 4}', '"123456789"');
-- Returns: {"\"123456789\" is longer than 4 characters"}

Schema Validation

Verify that a schema is well-formed before using it:

SELECT jsonschema_is_valid('{
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "age":  {"type": "integer", "minimum": 0}
    },
    "required": ["name"]
}');
-- Returns: true
Last updated on