json_schema_validate
json_schema_validate · Validate JSON and JSONB data against JSON Schema in PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101017 | json_schema_validate | json_schema_validate | 0.1.0 | FEAT | PostgreSQL | C |
PostgreSQL · 14, 15, 16, 17, 18
Usage
Sources:
- Official README at the reviewed commit
- Version 0.1.0 SQL API
- Validation implementation
- Extension control file
json_schema_validate validates PostgreSQL json and jsonb values against a substantial, but incomplete, JSON Schema implementation. Use jsonschema_is_valid for a Boolean result, jsonschema_validate for structured errors, and jsonschema_compile when the same schema is reused many times. Version 0.1.0 requires PostgreSQL 14 or later.
Core Workflow
For valid input, the reviewed implementation of jsonschema_validate returns an empty array []; for invalid input it returns an array of objects containing a path and message. Some source comments incorrectly say valid input returns SQL NULL, so rely on the implementation and regression-test the packaged build.
Main Objects
jsonschema_is_valid and jsonschema_validate have overloads for json, jsonb, and the compiled jsonschema_compiled type. jsonschema_compile(jsonb) parses a schema once and caches regular expressions for repeated validation. The functions are declared immutable, strict, and parallel-safe, making constant schemas suitable for CHECK constraints.
Schema Scope and Caveats
The implementation covers common type, object, array, string, numeric, composition, conditional, format, and local-reference keywords. It does not implement tuple-style prefixItems, dependency keywords, unevaluated-property or unevaluated-item keywords, external references, or dynamic references. Only local JSON Pointer references are supported, and unknown formats are ignored.
Unsupported or ignored keywords can make a document pass when a full standards implementation would reject it. Pin and test the exact schema vocabulary before using the extension as an integrity or security boundary, and keep resource limits in mind for deeply nested schemas, large arrays, complex regular expressions, or many accumulated validation errors.