Skip to content

jsonschema

JSON Schema validation functions for PostgreSQL

jsonschema : JSON Schema validation functions for PostgreSQL

Overview

ID Extension Package Version Category License Language
2760 jsonschema jsonschema 0.1.9 FEAT MIT Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r No Yes No Yes yes no
Distinct from Supabase pg_jsonschema.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT PIGSTY 0.1.9 18 17 16 15 14 jsonschema -
RPM PIGSTY 0.1.9 18 17 16 15 14 jsonschema_$v -
DEB PIGSTY 0.1.9 18 17 16 15 14 postgresql-$v-jsonschema -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
el8.aarch64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
el9.x86_64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
el9.aarch64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
el10.x86_64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
el10.aarch64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
d12.x86_64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
d12.aarch64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
d13.x86_64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
d13.aarch64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
u22.x86_64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
u22.aarch64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
u24.x86_64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
u24.aarch64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
u26.x86_64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
u26.aarch64 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9 PIGSTY 0.1.9
Package Version OS ORG SIZE File URL
jsonschema_18 0.1.9 el8.x86_64 pigsty 1.7 MiB jsonschema_18-0.1.9-3PIGSTY.el8.x86_64.rpm
jsonschema_18 0.1.9 el8.aarch64 pigsty 1.6 MiB jsonschema_18-0.1.9-3PIGSTY.el8.aarch64.rpm
jsonschema_18 0.1.9 el9.x86_64 pigsty 1.7 MiB jsonschema_18-0.1.9-3PIGSTY.el9.x86_64.rpm
jsonschema_18 0.1.9 el9.aarch64 pigsty 1.7 MiB jsonschema_18-0.1.9-3PIGSTY.el9.aarch64.rpm
jsonschema_18 0.1.9 el10.x86_64 pigsty 1.7 MiB jsonschema_18-0.1.9-3PIGSTY.el10.x86_64.rpm
jsonschema_18 0.1.9 el10.aarch64 pigsty 1.7 MiB jsonschema_18-0.1.9-3PIGSTY.el10.aarch64.rpm
postgresql-18-jsonschema 0.1.9 d12.x86_64 pigsty 1.4 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~bookworm_amd64.deb
postgresql-18-jsonschema 0.1.9 d12.aarch64 pigsty 1.2 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~bookworm_arm64.deb
postgresql-18-jsonschema 0.1.9 d13.x86_64 pigsty 1.4 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~trixie_amd64.deb
postgresql-18-jsonschema 0.1.9 d13.aarch64 pigsty 1.2 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~trixie_arm64.deb
postgresql-18-jsonschema 0.1.9 u22.x86_64 pigsty 1.5 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~jammy_amd64.deb
postgresql-18-jsonschema 0.1.9 u22.aarch64 pigsty 1.4 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~jammy_arm64.deb
postgresql-18-jsonschema 0.1.9 u24.x86_64 pigsty 1.5 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~noble_amd64.deb
postgresql-18-jsonschema 0.1.9 u24.aarch64 pigsty 1.4 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~noble_arm64.deb
postgresql-18-jsonschema 0.1.9 u26.x86_64 pigsty 1.5 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~resolute_amd64.deb
postgresql-18-jsonschema 0.1.9 u26.aarch64 pigsty 1.4 MiB postgresql-18-jsonschema_0.1.9-3PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
jsonschema_17 0.1.9 el8.x86_64 pigsty 1.7 MiB jsonschema_17-0.1.9-3PIGSTY.el8.x86_64.rpm
jsonschema_17 0.1.9 el8.aarch64 pigsty 1.6 MiB jsonschema_17-0.1.9-3PIGSTY.el8.aarch64.rpm
jsonschema_17 0.1.9 el9.x86_64 pigsty 1.7 MiB jsonschema_17-0.1.9-3PIGSTY.el9.x86_64.rpm
jsonschema_17 0.1.9 el9.aarch64 pigsty 1.7 MiB jsonschema_17-0.1.9-3PIGSTY.el9.aarch64.rpm
jsonschema_17 0.1.9 el10.x86_64 pigsty 1.7 MiB jsonschema_17-0.1.9-3PIGSTY.el10.x86_64.rpm
jsonschema_17 0.1.9 el10.aarch64 pigsty 1.7 MiB jsonschema_17-0.1.9-3PIGSTY.el10.aarch64.rpm
postgresql-17-jsonschema 0.1.9 d12.x86_64 pigsty 1.4 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~bookworm_amd64.deb
postgresql-17-jsonschema 0.1.9 d12.aarch64 pigsty 1.2 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~bookworm_arm64.deb
postgresql-17-jsonschema 0.1.9 d13.x86_64 pigsty 1.4 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~trixie_amd64.deb
postgresql-17-jsonschema 0.1.9 d13.aarch64 pigsty 1.2 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~trixie_arm64.deb
postgresql-17-jsonschema 0.1.9 u22.x86_64 pigsty 1.5 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~jammy_amd64.deb
postgresql-17-jsonschema 0.1.9 u22.aarch64 pigsty 1.4 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~jammy_arm64.deb
postgresql-17-jsonschema 0.1.9 u24.x86_64 pigsty 1.5 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~noble_amd64.deb
postgresql-17-jsonschema 0.1.9 u24.aarch64 pigsty 1.4 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~noble_arm64.deb
postgresql-17-jsonschema 0.1.9 u26.x86_64 pigsty 1.5 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~resolute_amd64.deb
postgresql-17-jsonschema 0.1.9 u26.aarch64 pigsty 1.4 MiB postgresql-17-jsonschema_0.1.9-3PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
jsonschema_16 0.1.9 el8.x86_64 pigsty 1.7 MiB jsonschema_16-0.1.9-3PIGSTY.el8.x86_64.rpm
jsonschema_16 0.1.9 el8.aarch64 pigsty 1.6 MiB jsonschema_16-0.1.9-3PIGSTY.el8.aarch64.rpm
jsonschema_16 0.1.9 el9.x86_64 pigsty 1.7 MiB jsonschema_16-0.1.9-3PIGSTY.el9.x86_64.rpm
jsonschema_16 0.1.9 el9.aarch64 pigsty 1.7 MiB jsonschema_16-0.1.9-3PIGSTY.el9.aarch64.rpm
jsonschema_16 0.1.9 el10.x86_64 pigsty 1.7 MiB jsonschema_16-0.1.9-3PIGSTY.el10.x86_64.rpm
jsonschema_16 0.1.9 el10.aarch64 pigsty 1.7 MiB jsonschema_16-0.1.9-3PIGSTY.el10.aarch64.rpm
postgresql-16-jsonschema 0.1.9 d12.x86_64 pigsty 1.4 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~bookworm_amd64.deb
postgresql-16-jsonschema 0.1.9 d12.aarch64 pigsty 1.2 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~bookworm_arm64.deb
postgresql-16-jsonschema 0.1.9 d13.x86_64 pigsty 1.4 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~trixie_amd64.deb
postgresql-16-jsonschema 0.1.9 d13.aarch64 pigsty 1.2 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~trixie_arm64.deb
postgresql-16-jsonschema 0.1.9 u22.x86_64 pigsty 1.5 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~jammy_amd64.deb
postgresql-16-jsonschema 0.1.9 u22.aarch64 pigsty 1.4 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~jammy_arm64.deb
postgresql-16-jsonschema 0.1.9 u24.x86_64 pigsty 1.5 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~noble_amd64.deb
postgresql-16-jsonschema 0.1.9 u24.aarch64 pigsty 1.4 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~noble_arm64.deb
postgresql-16-jsonschema 0.1.9 u26.x86_64 pigsty 1.5 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~resolute_amd64.deb
postgresql-16-jsonschema 0.1.9 u26.aarch64 pigsty 1.4 MiB postgresql-16-jsonschema_0.1.9-3PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
jsonschema_15 0.1.9 el8.x86_64 pigsty 1.7 MiB jsonschema_15-0.1.9-3PIGSTY.el8.x86_64.rpm
jsonschema_15 0.1.9 el8.aarch64 pigsty 1.6 MiB jsonschema_15-0.1.9-3PIGSTY.el8.aarch64.rpm
jsonschema_15 0.1.9 el9.x86_64 pigsty 1.7 MiB jsonschema_15-0.1.9-3PIGSTY.el9.x86_64.rpm
jsonschema_15 0.1.9 el9.aarch64 pigsty 1.7 MiB jsonschema_15-0.1.9-3PIGSTY.el9.aarch64.rpm
jsonschema_15 0.1.9 el10.x86_64 pigsty 1.7 MiB jsonschema_15-0.1.9-3PIGSTY.el10.x86_64.rpm
jsonschema_15 0.1.9 el10.aarch64 pigsty 1.7 MiB jsonschema_15-0.1.9-3PIGSTY.el10.aarch64.rpm
postgresql-15-jsonschema 0.1.9 d12.x86_64 pigsty 1.4 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~bookworm_amd64.deb
postgresql-15-jsonschema 0.1.9 d12.aarch64 pigsty 1.2 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~bookworm_arm64.deb
postgresql-15-jsonschema 0.1.9 d13.x86_64 pigsty 1.4 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~trixie_amd64.deb
postgresql-15-jsonschema 0.1.9 d13.aarch64 pigsty 1.2 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~trixie_arm64.deb
postgresql-15-jsonschema 0.1.9 u22.x86_64 pigsty 1.5 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~jammy_amd64.deb
postgresql-15-jsonschema 0.1.9 u22.aarch64 pigsty 1.4 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~jammy_arm64.deb
postgresql-15-jsonschema 0.1.9 u24.x86_64 pigsty 1.5 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~noble_amd64.deb
postgresql-15-jsonschema 0.1.9 u24.aarch64 pigsty 1.4 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~noble_arm64.deb
postgresql-15-jsonschema 0.1.9 u26.x86_64 pigsty 1.5 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~resolute_amd64.deb
postgresql-15-jsonschema 0.1.9 u26.aarch64 pigsty 1.4 MiB postgresql-15-jsonschema_0.1.9-3PIGSTY~resolute_arm64.deb
Package Version OS ORG SIZE File URL
jsonschema_14 0.1.9 el8.x86_64 pigsty 1.7 MiB jsonschema_14-0.1.9-3PIGSTY.el8.x86_64.rpm
jsonschema_14 0.1.9 el8.aarch64 pigsty 1.6 MiB jsonschema_14-0.1.9-3PIGSTY.el8.aarch64.rpm
jsonschema_14 0.1.9 el9.x86_64 pigsty 1.7 MiB jsonschema_14-0.1.9-3PIGSTY.el9.x86_64.rpm
jsonschema_14 0.1.9 el9.aarch64 pigsty 1.7 MiB jsonschema_14-0.1.9-3PIGSTY.el9.aarch64.rpm
jsonschema_14 0.1.9 el10.x86_64 pigsty 1.7 MiB jsonschema_14-0.1.9-3PIGSTY.el10.x86_64.rpm
jsonschema_14 0.1.9 el10.aarch64 pigsty 1.7 MiB jsonschema_14-0.1.9-3PIGSTY.el10.aarch64.rpm
postgresql-14-jsonschema 0.1.9 d12.x86_64 pigsty 1.4 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~bookworm_amd64.deb
postgresql-14-jsonschema 0.1.9 d12.aarch64 pigsty 1.2 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~bookworm_arm64.deb
postgresql-14-jsonschema 0.1.9 d13.x86_64 pigsty 1.4 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~trixie_amd64.deb
postgresql-14-jsonschema 0.1.9 d13.aarch64 pigsty 1.2 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~trixie_arm64.deb
postgresql-14-jsonschema 0.1.9 u22.x86_64 pigsty 1.5 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~jammy_amd64.deb
postgresql-14-jsonschema 0.1.9 u22.aarch64 pigsty 1.4 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~jammy_arm64.deb
postgresql-14-jsonschema 0.1.9 u24.x86_64 pigsty 1.5 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~noble_amd64.deb
postgresql-14-jsonschema 0.1.9 u24.aarch64 pigsty 1.4 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~noble_arm64.deb
postgresql-14-jsonschema 0.1.9 u26.x86_64 pigsty 1.5 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~resolute_amd64.deb
postgresql-14-jsonschema 0.1.9 u26.aarch64 pigsty 1.4 MiB postgresql-14-jsonschema_0.1.9-3PIGSTY~resolute_arm64.deb

Source

pig build pkg 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 jsonschema;		# install via package name, for the active PG version

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

Create this extension with:

CREATE EXTENSION jsonschema;

Usage

Sources:

jsonschema validates JSON and JSONB values against JSON Schema inside PostgreSQL. It is the theory/pg-jsonschema-boon extension and is distinct from Supabase pg_jsonschema, although it provides compatibility wrappers named json_matches_schema() and jsonb_matches_schema().

The extension supports JSON Schema draft 4, draft 6, draft 7, draft 2019-09, and draft 2020-12 through the Rust boon validator. It has no runtime dependency beyond PostgreSQL.

Latest-check note: upstream main currently points at the same commit as tag v0.1.9, so this refresh found no material user-facing delta beyond replacing the stale generated-SQL source link.

Validate a Schema and a Document

CREATE EXTENSION IF NOT EXISTS jsonschema;

SELECT jsonschema_is_valid(
  '{
     "type": "object",
     "required": ["name", "email"],
     "properties": {
       "name":  { "type": "string" },
       "age":   { "type": "number", "minimum": 0 },
       "email": { "type": "string", "format": "email" }
     }
   }'::json
);

SELECT jsonschema_validates(
  '{"name":"Amos Burton","email":"[email protected]"}'::json,
  '{
     "type": "object",
     "required": ["name", "email"],
     "properties": {
       "name":  { "type": "string" },
       "email": { "type": "string", "format": "email" }
     }
   }'::json
);

jsonschema_is_valid(schema) returns whether the schema itself compiles and validates against the selected draft. jsonschema_validates(data, schema) returns whether the JSON/JSONB value satisfies the schema.

Check Constraints

CREATE TABLE customer_profile (
  id       bigserial PRIMARY KEY,
  profile  jsonb NOT NULL,
  CHECK (
    jsonschema_validates(
      profile,
      '{
         "type": "object",
         "required": ["email"],
         "properties": {
           "email": { "type": "string", "format": "email" },
           "tags":  {
             "type": "array",
             "items": { "type": "string", "maxLength": 16 }
           }
         }
       }'::jsonb
    )
  )
);

Use constraints when the database should reject malformed JSON documents at write time.

Composed Schemas

SELECT jsonschema_validates(
  jsonb_build_object(
    'first_name', 'Naomi',
    'last_name', 'Nagata',
    'shipping_address', jsonb_build_object(
      'street_address', '1 Rocinante Way',
      'city', 'Ceres Station',
      'state', 'The Belt'
    )
  ),
  'https://example.com/schemas/customer',
  '{
     "$id": "https://example.com/schemas/address",
     "type": "object",
     "required": ["street_address", "city", "state"],
     "properties": {
       "street_address": { "type": "string" },
       "city": { "type": "string" },
       "state": { "type": "string" }
     }
   }'::jsonb,
  '{
     "$id": "https://example.com/schemas/customer",
     "type": "object",
     "required": ["first_name", "last_name", "shipping_address"],
     "properties": {
       "first_name": { "type": "string" },
       "last_name": { "type": "string" },
       "shipping_address": { "$ref": "/schemas/address" }
     }
   }'::jsonb
);

The id overloads let multiple schemas reference each other by $id, which is useful for componentized JSON Schema definitions.

Compatibility Functions

SELECT json_matches_schema(
  '{"type":"string","maxLength":4}'::json,
  '"1234"'::json
);

SELECT jsonb_matches_schema(
  '{"type":"object","required":["id"]}'::json,
  '{"id":42}'::jsonb
);

These wrappers mirror the common pg_jsonschema argument order: schema first, instance second.

Draft Selection and Caveats

SET jsonschema.default_draft = 'V2020';
SET jsonschema.default_draft = 'V7';

If a schema omits $schema, jsonschema.default_draft controls the default draft. Supported values are V4, V6, V7, V2019, and V2020.

  • jsonschema_validates(data, schema) returns NULL if either argument is NULL.
  • Invalid or uncompilable schemas can raise errors in validation calls; failed document validation returns false and logs details at INFO.
  • jsonschema_is_valid(id, VARIADIC schemas) and jsonschema_validates(data, id, VARIADIC schemas) require matching $id values for reliable composed-schema resolution.