Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gavinwahl/postgres-json-schema
JSON Schema validation for PostgreSQL
https://github.com/gavinwahl/postgres-json-schema
Last synced: 4 months ago
JSON representation
JSON Schema validation for PostgreSQL
- Host: GitHub
- URL: https://github.com/gavinwahl/postgres-json-schema
- Owner: gavinwahl
- License: postgresql
- Created: 2016-10-08T04:15:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-10T20:50:58.000Z (9 months ago)
- Last Synced: 2023-10-11T01:51:44.991Z (9 months ago)
- Language: PLpgSQL
- Homepage:
- Size: 11.7 KB
- Stars: 452
- Watchers: 18
- Forks: 33
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- JSON-Schema-Test-Suite?utm_source=awesome-jsonschema - postgres-json-schema
- awesome-stars - gavinwahl/postgres-json-schema - JSON Schema validation for PostgreSQL (PLpgSQL)
README
# postgres-json-schema
[![Build Status](https://travis-ci.org/gavinwahl/postgres-json-schema.svg?branch=master)](https://travis-ci.org/gavinwahl/postgres-json-schema)
postgres-json-schema allows validation of [JSON
schemas](http://json-schema.org/) in PostgreSQL. It is implemented as a
PL/pgSQL function and you can use it as a check constraint to validate the
format of your JSON columns.postgres-json-schema supports the entire JSON schema draft v4 spec, except for
remote (http) references. It's tested against the official
[JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite).# Installation
postgres-json-schema is packaged as an PGXS extension. To install, just run
`make install` as root, then `CREATE EXTENSION "postgres-json-schema";` as the
database superuser.# Example
CREATE TABLE example (id serial PRIMARY KEY, data jsonb);
ALTER TABLE example ADD CONSTRAINT data_is_valid CHECK (validate_json_schema('{"type": "object"}', data));INSERT INTO example (data) VALUES ('{}');
-- INSERT 0 1INSERT INTO example (data) VALUES ('1');
-- ERROR: new row for relation "example" violates check constraint "data_is_valid"
-- DETAIL: Failing row contains (2, 1).