-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
91 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-- pg_jsonschema-compatible functions | ||
-- Valid JSON | ||
SELECT json_matches_schema('{"type": "object"}', '{"hi": "there"}'); | ||
json_matches_schema | ||
--------------------- | ||
t | ||
(1 row) | ||
|
||
SELECT jsonb_matches_schema('{"type": "object"}', '{"hi": "there"}'); | ||
jsonb_matches_schema | ||
---------------------- | ||
t | ||
(1 row) | ||
|
||
-- Invalid JSON | ||
SELECT json_matches_schema('{"type": "object"}', '["not an object"]'); | ||
INFO: jsonschema validation failed with file:///schema.json# | ||
- at '': want object, but got array | ||
json_matches_schema | ||
--------------------- | ||
f | ||
(1 row) | ||
|
||
SELECT jsonb_matches_schema('{"type": "object"}', '["not an object"]'); | ||
INFO: jsonschema validation failed with file:///schema.json# | ||
- at '': want object, but got array | ||
jsonb_matches_schema | ||
---------------------- | ||
f | ||
(1 row) | ||
|
||
-- Invalid schema | ||
SELECT json_matches_schema('{"type": "nonesuch"}', '{"x": "y"}'); | ||
ERROR: file:///schema.json is not valid against metaschema: jsonschema validation failed with https://json-schema.org/draft/2020-12/schema# | ||
- at '/type': anyOf failed | ||
- at '/type': value must be one of 'array', 'boolean', 'integer', 'null', 'number', 'object', 'string' | ||
- at '/type': want array, but got string | ||
SELECT jsonb_matches_schema('{"type": "nonesuch"}', '{"x": "y"}'); | ||
ERROR: file:///schema.json is not valid against metaschema: jsonschema validation failed with https://json-schema.org/draft/2020-12/schema# | ||
- at '/type': anyOf failed | ||
- at '/type': value must be one of 'array', 'boolean', 'integer', 'null', 'number', 'object', 'string' | ||
- at '/type': want array, but got string | ||
-- NULL instance | ||
SELECT json_matches_schema('{"type": "object"}', NULL); | ||
json_matches_schema | ||
--------------------- | ||
|
||
(1 row) | ||
|
||
SELECT jsonb_matches_schema('{"type": "object"}', NULL); | ||
jsonb_matches_schema | ||
---------------------- | ||
|
||
(1 row) | ||
|
||
-- NULL schema | ||
SELECT json_matches_schema(NULL, '{"x": "y"}'); | ||
json_matches_schema | ||
--------------------- | ||
|
||
(1 row) | ||
|
||
SELECT jsonb_matches_schema(NULL, '{"x": "y"}'); | ||
jsonb_matches_schema | ||
---------------------- | ||
|
||
(1 row) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- pg_jsonschema-compatible functions | ||
|
||
-- Valid JSON | ||
SELECT json_matches_schema('{"type": "object"}', '{"hi": "there"}'); | ||
SELECT jsonb_matches_schema('{"type": "object"}', '{"hi": "there"}'); | ||
|
||
-- Invalid JSON | ||
SELECT json_matches_schema('{"type": "object"}', '["not an object"]'); | ||
SELECT jsonb_matches_schema('{"type": "object"}', '["not an object"]'); | ||
|
||
-- Invalid schema | ||
SELECT json_matches_schema('{"type": "nonesuch"}', '{"x": "y"}'); | ||
SELECT jsonb_matches_schema('{"type": "nonesuch"}', '{"x": "y"}'); | ||
|
||
-- NULL instance | ||
SELECT json_matches_schema('{"type": "object"}', NULL); | ||
SELECT jsonb_matches_schema('{"type": "object"}', NULL); | ||
|
||
-- NULL schema | ||
SELECT json_matches_schema(NULL, '{"x": "y"}'); | ||
SELECT jsonb_matches_schema(NULL, '{"x": "y"}'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
-- pg_jsonschema-compatible functions | ||
SELECT json_matches_schema('{"type": "object"}'::json, '{"hi": "there"}'::json); | ||
SELECT jsonb_matches_schema('{"type": "object"}'::json, '{"hi": "there"}'::jsonb); | ||
|