You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -17,14 +17,85 @@ postgres-json-schema is packaged as an PGXS extension. To install, just run
17
17
`make install` as root, then `CREATE EXTENSION "postgres-json-schema";` as the
18
18
database superuser.
19
19
20
+
# Usage
21
+
22
+
## Types
23
+
-`json_schema_validation_result` A composite type which contains error messages and path (an array to the path) within json data where the validation failed
24
+
#### contains the following attributes
25
+
-`path` a `text[]` to the path where the validation failed
26
+
-`error` the validation error message
27
+
28
+
## Functions
29
+
30
+
#### Functions accepting a argument `string_as_number` controlling whether a schema expecting a number may contain a valid number as a string. This is useful when dealing with for example python Decimal, which most implementations serialize it to json as a quoted string not to lose decimal precision.
31
+
32
+
-```sql
33
+
-- Returns bool
34
+
validate_json_schema(schema jsonb, data jsonb, string_as_number bool)
35
+
```
36
+
-```sql
37
+
-- Returns ARRAY json_schema_validation_result[]
38
+
get_json_schema_validations(schema jsonb, data jsonb, string_as_number bool)
39
+
```
40
+
-```sql
41
+
-- Returns true if valid,
42
+
-- otherwise raises a check_constraint exception, this is useful when you want to get a detailed
43
+
-- error knowing which part of the json document failed to validate.
44
+
json_schema_check_constraint(
45
+
schema jsonb,
46
+
data jsonb,
47
+
string_as_number bool default false,
48
+
table_name text default '', -- if you need to set the value for TABLE in the PG_EXCEPTION_CONTEXT
49
+
column_name text default ''-- if you need to set the value for COLUMN in the PG_EXCEPTION_CONTEXT
50
+
)
51
+
```
52
+
-`json_schema_resolve_refs( schema )`
53
+
54
+
When dealing with a JSON schema that has `$id` uri values being used in `$ref`,
55
+
there is a convenient function to resolve those references
56
+
```sql
57
+
validate_json_schema( json_schema_resolve_refs( schema ), data );
0 commit comments