Skip to content

jefbarn/pgx_json_schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgx_json_schema

A JSON Schema validator for Postgres implemented in Rust

This repo is a lightweight connection between the following excellent packages:

Installation:

  1. Install Rust

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

  2. Install PGX

    cargo install cargo-pgx

  3. Download this repo

    curl -L 'https://github.com/jefbarn/pgx_json_schema/archive/refs/tags/0.1.0.tar.gz' | tar -xz --strip-components=1

  4. Build and install the extension package

    cargo pgx package

  5. Enable the extension in your database

    create extension pgx_json_schema;

How to use:

select * from json_schema_is_valid('{"maxLength": 5}'::jsonb, '"foobar"'::jsonb);

json_schema_is_valid
----------------------
f
select * from json_schema_get_errors('{"maxLength": 5}'::jsonb, '"foobar"'::jsonb);

error_value |             description              |        details         | instance_path | schema_path
------------+--------------------------------------+------------------------+---------------+-------------
"foobar"    | "foobar" is longer than 5 characters | MaxLength { limit: 5 } |               | /maxLength

Things left to do:

  • Use shared memory to store compiled validator (potential performance gain)
  • More testing
  • Benchmarking
  • Add more schema types like JTD and Avro

Prior Art

About

JSON Schema validation for Postgres

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •