is_jsonb_valid

This Release
is_jsonb_valid 0.0.1
Date
Status
Stable
Abstract
Validate json schemas
Description
Validate the integrity of jsons in the database making sure they validate against an schema
Released By
furstenheim
License
MIT
Resources
Special Files
Tags

Extensions

jsonb_deep_sum 0.0.1

Documentation

README
README

README

Is jsonb valid

is_jsonb_valid is a native PostgreSQL extension to validate json schemas following Draft4. The extension exposes only one function is_jsonb_valid(schema jsonb, data jsonb) which returns a boolean depending on the success of the validation.

Examples:

SELECT is_jsonb_valid('{"type": "number"}', '1');
> t
SELECT is_jsonb_valid('{"type": "object"}', '1');
> f

It passes all JSON-Schema-Test-Suite, with the notable exception of $refRemote.

Testing and Installation

In the directory of the project do:

make install && make installcheck

This will compile the extension and run the tests. Later in psql run:

CREATE EXTENSION is_jsonb_valid;

Benchmarking

Benchmarking is always tricky, I've tried to check against a real world example, in particular tweets. The only other extension that I know for this purpose is postgres-json-schema. For more information on how to run the benchmarks check ./tools/README.md

| Numbers of tweets | is_jsonb_valid (ms) | postgres-json-schema (ms) | Improvement (times) | --------------- | ---------------- | --------------- | ------- | | 10 | 34.270 | 192.678 | 5.6 | | 100 | 206.378 | 1975.543 | 9.6 | 10000 | 8911.354 | 203172.464 | 22.8

Disclaimer

This project is a based on postgres-json-schema. It has been written from scratch in C (original was written in SQL).