Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@


## API
Three SQL functions:
This extension exposes the following four SQL functions:
- json_matches_schema
- jsonb_matches_schema (note the **jsonb** in front)
- jsonschema_is_valid
- jsonschema_validation_errors

With the following signatures
```sql
Expand All @@ -38,6 +39,11 @@ and
-- Validates whether a json *schema* is valid
jsonschema_is_valid(schema json) returns bool
```
and
```sql
-- Returns an array of errors if a *schema* is invalid
jsonschema_validation_errors(schema json, instance json) returns text[]
```

## Usage
Those functions can be used to constrain `json` and `jsonb` columns to conform to a schema.
Expand Down Expand Up @@ -81,6 +87,11 @@ values ('{"tags": [1, 3]}');
-- Result:
-- ERROR: new row for relation "customer" violates check constraint "customer_metadata_check"
-- DETAIL: Failing row contains (2, {"tags": [1, 3]}).

-- Example: jsonschema_validation_errors
select jsonschema_validation_errors('{"maxLength": 4}', '"123456789"');
-- Result:
-- ERROR: "123456789" is longer than 4 characters
```

## JSON Schema Support
Expand Down