百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

pg_jsonschema

> 编程语言
开源

提供 JSON Schema 验证的 PostgreSQL 扩展

1.2K stars0 点赞2 次浏览
访问官网GitHub

工具介绍

提供 JSON Schema 验证的 PostgreSQL 扩展

pg_jsonschema


源代码: https://github.com/supabase/pg_jsonschema

摘要

pg_jsonschema 是一个 PostgreSQL 扩展,添加了对 json 和 jsonb 数据类型的 JSON 规范 验证的支持。

API

此扩展暴露了以下四个 SQL 函数:

  • json_matches_schema
  • jsonb_matches_schema (请注意前面的 jsonb)
  • jsonschema_is_valid
  • jsonschema_validation_errors 使用以下签名
sql
-- Validates a json *instance* against a *schema*
json_matches_schema(schema json, instance json) returns bool

而且

sql
-- Validates a jsonb *instance* against a *schema*
jsonb_matches_schema(schema json, instance jsonb) returns bool

而且

sql
-- Validates whether a json *schema* is valid
jsonschema_is_valid(schema json) returns bool

而且

sql
-- Returns an array of errors if a *schema* is invalid
jsonschema_validation_errors(schema json, instance json) returns text[]

编译的架构类型

对于对同一模式进行重复验证,请将其转换为 jsonschema。验证器会根据调用位置进行编译和缓存,从而避免在每一行上重新编译。

sql
-- Validates a json instance against a pre-compiled schema
json_matches_compiled_schema(schema jsonschema, instance json) returns bool

-- Validates a jsonb instance against a pre-compiled schema
jsonb_matches_compiled_schema(schema jsonschema, instance jsonb) returns bool

-- Returns validation errors for a json instance
jsonschema_validation_errors_compiled(schema jsonschema, instance json) returns text[]

-- Returns validation errors for a jsonb instance
jsonb_validation_errors_compiled(schema jsonschema, instance jsonb) returns text[]

使用方法

这些函数可用于约束 json 和 jsonb 列以符合一个模式。例如:

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言