---
title: "pg_jsonschema: JSON Schema support for Postgres"
description: "pg_jsonschema is a Postgres extension that validates `json` and `jsonb` values against a JSON Schema through two functions, `json_matches_schema` and `jsonb_matches_schema`."
url: "https://swe.quest/articles/pg-jsonschema-json-schema-support-for-postgres-489ffe5b7545ddca"
canonical: "https://supabase.com/blog/pg-jsonschema-a-postgres-extension-for-json-validation"
source: "Supabase"
published: "2022-08-19"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 4
tags: ["postgres","databases"]
---

# pg\_jsonschema: JSON Schema support for Postgres

A post on [Supabase](https://swe.quest/sources/supabase.md), published 2022-08-19, 4 min read, Announcement. Original: [https://supabase.com/blog/pg-jsonschema-a-postgres-extension-for-json-validation](https://supabase.com/blog/pg-jsonschema-a-postgres-extension-for-json-validation)

## Summary

pg\_jsonschema is a Postgres extension that validates \`json\` and \`jsonb\` values against a JSON Schema through two functions, \`json\_matches\_schema\` and \`jsonb\_matches\_schema\`. Used inside a check constraint, it keeps the flexibility of document columns, such as storing raw webhook payloads instead of normalizing them into many joined tables, while still enforcing type, required-field and no-extra-properties rules. In the example, an unconstrained \`json\` column handled only 2 of 8 test inputs correctly, and the schema-backed check constraint handled all 8. It is available on Supabase via \`create extension pg\_jsonschema\` or through Docker Compose.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)

## Prerequisites

- Postgres check constraints ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- JSON/JSONB data types

## Keywords

pg\_jsonschema, JSON Schema, PostgreSQL, Supabase, jsonb

## Related posts

- [pg\_graphql: A GraphQL extension for PostgreSQL](https://swe.quest/articles/pg-graphql-a-graphql-extension-for-postgresql-3a34efbe6d730fc2.md): Supabase · 2021-12-03 · Medium · 4 min read · GraphQL, PostgreSQL, API design
  pg\_graphql is an open-source PostgreSQL extension, written in C and SQL, that reflects a GraphQL schema from existing tables and resolves queries entirely inside the database.
- [How pg\_graphql works](https://swe.quest/articles/how-pg-graphql-works-70dff1dd9d5a0c27.md): Supabase · 2024-01-24 · Medium · 9 min read · GraphQL, PostgreSQL, Rust, Compilers
  pg\_graphql is a Rust-based Postgres extension that reflects the SQL schema as a GraphQL schema and serves queries through a \`graphql.resolve\` SQL function, with no separate server.
- [PostgREST 13](https://swe.quest/articles/postgrest-13-412584efa365a837.md): Supabase · 2025-09-30 · Medium · 3 min read · PostgreSQL, API design, Search, Identity & auth
  PostgREST 13 adds spread syntax for to-many relationships so one-to-many and many-to-many joins can be returned as flat JSON arrays, automatic to\_tsvector conversion that enables full text search on text and json/jsonb columns (backed by a GIN index on the expression), and a maxAffected limit that throws an error when an update, delete or rpc touches too many rows.
- [pg\_graphql: Postgres functions now supported](https://swe.quest/articles/pg-graphql-postgres-functions-now-supported-279553dc083ab4d8.md): Supabase · 2023-12-12 · Medium · 4 min read · GraphQL, PostgreSQL, API design
  pg\_graphql 1.4+ reflects Postgres user-defined functions into the GraphQL schema, giving custom SQL logic a GraphQL entry point.
- [pg\_graphql v1.0](https://swe.quest/articles/pg-graphql-v1-0-5a4770d60b17d945.md): Supabase · 2022-12-16 · Medium · 5 min read · GraphQL, PostgreSQL, Rust, Performance engineering
  pg\_graphql, a PostgreSQL extension that compiles GraphQL requests into a single SQL query, reaches 1.0 with a SemVer backwards-compatibility guarantee.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
