{"id":13580308,"url":"https://github.com/supabase/pg_jsonschema","last_synced_at":"2026-01-27T13:05:18.008Z","repository":{"id":47301528,"uuid":"472775521","full_name":"supabase/pg_jsonschema","owner":"supabase","description":"PostgreSQL extension providing JSON Schema validation","archived":false,"fork":false,"pushed_at":"2026-01-23T10:27:15.000Z","size":179,"stargazers_count":1158,"open_issues_count":2,"forks_count":44,"subscribers_count":24,"default_branch":"master","last_synced_at":"2026-01-24T09:41:21.363Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/supabase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["supabase"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2022-03-22T13:17:28.000Z","updated_at":"2026-01-23T19:19:00.000Z","dependencies_parsed_at":"2023-10-05T01:36:46.174Z","dependency_job_id":"ced174ab-ee1c-474c-bb87-d16d5d718363","html_url":"https://github.com/supabase/pg_jsonschema","commit_stats":{"total_commits":63,"total_committers":15,"mean_commits":4.2,"dds":0.4920634920634921,"last_synced_commit":"dcbe58ebfe6712746162253770167cfa7a73667a"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/supabase/pg_jsonschema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fpg_jsonschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fpg_jsonschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fpg_jsonschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fpg_jsonschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supabase","download_url":"https://codeload.github.com/supabase/pg_jsonschema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fpg_jsonschema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28813239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T12:25:15.069Z","status":"ssl_error","status_checked_at":"2026-01-27T12:25:05.297Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:01:49.733Z","updated_at":"2026-01-27T13:05:17.995Z","avatar_url":"https://github.com/supabase.png","language":"Rust","funding_links":["https://github.com/sponsors/supabase"],"categories":["Rust","Shell"],"sub_categories":[],"readme":"# pg_jsonschema\n\n\u003cp\u003e\n\u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/postgresql-12+-blue.svg\" alt=\"PostgreSQL version\" height=\"18\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/supabase/pg_jsonschema/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/pypi/l/markdown-subtemplate.svg\" alt=\"License\" height=\"18\"\u003e\u003c/a\u003e\n\n\u003c/p\u003e\n\n---\n\n**Source Code**: \u003ca href=\"https://github.com/supabase/pg_jsonschema\" target=\"_blank\"\u003ehttps://github.com/supabase/pg_jsonschema\u003c/a\u003e\n\n---\n\n## Summary\n\n`pg_jsonschema` is a PostgreSQL extension adding support for [JSON schema](https://json-schema.org/) validation on `json` and `jsonb` data types.\n\n\n## API\nThis extension exposes the following four SQL functions:\n- json_matches_schema\n- jsonb_matches_schema (note the **jsonb** in front)\n- jsonschema_is_valid\n- jsonschema_validation_errors\n\nWith the following signatures\n```sql\n-- Validates a json *instance* against a *schema*\njson_matches_schema(schema json, instance json) returns bool\n```\nand\n```sql\n-- Validates a jsonb *instance* against a *schema*\njsonb_matches_schema(schema json, instance jsonb) returns bool\n```\nand\n```sql\n-- Validates whether a json *schema* is valid\njsonschema_is_valid(schema json) returns bool\n```\nand\n```sql\n-- Returns an array of errors if a *schema* is invalid\njsonschema_validation_errors(schema json, instance json) returns text[]\n```\n\n## Usage\nThose functions can be used to constrain `json` and `jsonb` columns to conform to a schema.\n\nFor example:\n```sql\ncreate extension pg_jsonschema;\n\ncreate table customer(\n    id serial primary key,\n    metadata json,\n\n    check (\n        json_matches_schema(\n            '{\n                \"type\": \"object\",\n                \"properties\": {\n                    \"tags\": {\n                        \"type\": \"array\",\n                        \"items\": {\n                            \"type\": \"string\",\n                            \"maxLength\": 16\n                        }\n                    }\n                }\n            }',\n            metadata\n        )\n    )\n);\n\n-- Example: Valid Payload\ninsert into customer(metadata)\nvalues ('{\"tags\": [\"vip\", \"darkmode-ui\"]}');\n-- Result:\n--   INSERT 0 1\n\n-- Example: Invalid Payload\ninsert into customer(metadata)\nvalues ('{\"tags\": [1, 3]}');\n-- Result:\n--   ERROR:  new row for relation \"customer\" violates check constraint \"customer_metadata_check\"\n--   DETAIL:  Failing row contains (2, {\"tags\": [1, 3]}).\n\n-- Example: jsonschema_validation_errors\nselect jsonschema_validation_errors('{\"maxLength\": 4}', '\"123456789\"');\n-- Result:\n--   ERROR: \"123456789\" is longer than 4 characters\n```\n\n## JSON Schema Support\n\npg_jsonschema is a (very) thin wrapper around the [jsonschema](https://docs.rs/jsonschema/latest/jsonschema/) rust crate. Visit their docs for full details on which drafts of the JSON Schema spec are supported.\n\n## Try it Out\n\nSpin up Postgres with pg_jsonschema installed in a docker container via `docker-compose up`. The database is available at `postgresql://postgres:password@localhost:5407/app`\n\n\n## Installation\n\n\nRequires:\n- [pgrx](https://github.com/tcdi/pgrx)\n\n\n```shell\ncargo pgrx run\n```\n\nwhich drops into a psql prompt.\n```psql\npsql (13.6)\nType \"help\" for help.\n\npg_jsonschema=# create extension pg_jsonschema;\nCREATE EXTENSION\n\npg_jsonschema=# select json_matches_schema('{\"type\": \"object\"}', '{}');\n json_matches_schema \n---------------------\n t\n(1 row)\n```\n\nfor more complete installation guidelines see the [pgrx](https://github.com/tcdi/pgrx) docs.\n\n\n## Prior Art\n\n[postgres-json-schema](https://github.com/gavinwahl/postgres-json-schema) - JSON Schema Postgres extension written in PL/pgSQL\n\n[is_jsonb_valid](https://github.com/furstenheim/is_jsonb_valid) - JSON Schema Postgres extension written in C\n\n[pgx_json_schema](https://github.com/jefbarn/pgx_json_schema) - JSON Schema Postgres extension written with pgrx + jsonschema\n\n\n## Benchmark\n\n\n#### System\n- 2021 MacBook Pro M1 Max (32GB)\n- macOS 14.2\n- PostgreSQL 16.2\n\n### Setup\nValidating the following schema on 20k unique inserts\n\n```json\n{\n    \"type\": \"object\",\n    \"properties\": {\n        \"a\": {\"type\": \"number\"},\n        \"b\": {\"type\": \"string\"}\n    }\n}\n```\n\n```sql\ncreate table bench_test_pg_jsonschema(\n    meta jsonb,\n    check (\n        jsonb_matches_schema(\n            '{\"type\": \"object\", \"properties\": {\"a\": {\"type\": \"number\"}, \"b\": {\"type\": \"string\"}}}',\n            meta\n        )\n    )\n);\n\ninsert into bench_test_pg_jsonschema(meta)\nselect\n    json_build_object(\n        'a', i,\n        'b', i::text\n    )\nfrom\n    generate_series(1, 20000) t(i);\n-- Query Completed in 351 ms \n```\nfor comparison, the equivalent test using postgres-json-schema's `validate_json_schema` function ran in 5.54 seconds. pg_jsonschema's ~15x speedup on this example JSON schema grows quickly as the schema becomes more complex.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase%2Fpg_jsonschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupabase%2Fpg_jsonschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase%2Fpg_jsonschema/lists"}