CREATE EXTENSION is_jsonb_valid; SELECT is_jsonb_valid('{}', '{}'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"not": {"type": "object"}}', '1'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"not": {"type": "object"}}', '{}'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"type": "object"}', '{}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"type": "object"}', '2'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"type": "object"}', '{"a": 1}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"type": "number"}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"type": "integer"}', '2'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"enum": [ 1, 2, 3, {"a": 2}]}', '1'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"enum": [ 1, 2, 3, {"a": 2}]}', '{"a": 2}'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"enum": [ 1, 2, 3, {"a": 2}]}', '{"a": 1}'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"minLength": 2}', '"abc"'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"minLength": 2}', '"a"'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"maxLength": 2}', '"a"'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"maxLength": 2}', '"abc"'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{ "dependencies": { "a": { "properties": { "x": { "type": "integer" } } } } }', '{ "a": "whatever", "x": 131 }'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{ "dependencies": { "a": { "properties": { "x": { "type": "integer" } } } } }', '{ "a": true, "x": 1.1 }'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{ "dependencies": { "a": "b", "c": [ "d", "e" ] } }', '{ "a": true, "b": null }'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{ "dependencies": { "a": "b", "c": [ "d", "e" ] } }', '{ "c": false, "d": 31 }'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{ "dependencies": { "a": "b", "c": [ "d", "e" ] } }', '{ "c": false, "d": 31, "e": {"a": 1} }'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{ "patternProperties": { "f.*o": {"type": "integer"} }}', '{"foo": 1}'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{ "patternProperties": { "f.*o": {"type": "integer"} }}', '{"foo": "bar", "fooooo": 2}'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{ "patternProperties": { "f.*o": {"type": "integer"} }, "properties": {"a": {"type": "integer"}}, "additionalProperties": false}', '{"foo": 1, "a": 2.5}'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{ "patternProperties": { "f.*o": {"type": "integer"} }, "properties": {"a": {"type": "integer"}}, "additionalProperties": false}', '{"foo": 1, "a": 2}'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{ "patternProperties": { "f.*o": {"type": "integer"} }, "properties": {"a": {"type": "integer"}}, "additionalProperties": true}', '{"foo": 1, "a": 2}'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{ "patternProperties": { "f.*o": {"type": "integer"} }, "properties": {"a": {"type": "integer"}}, "additionalProperties": true}', '{"foo": 1, "a": 2, "b": false}'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{ "patternProperties": { "f.*o": {"type": "integer"} }, "properties": {"a": {"type": "integer"}}, "additionalProperties": {"type": "boolean"}}', '{"foo": 1, "a": 2, "b": false}'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{ "patternProperties": { "f.*o": {"type": "integer"} }, "properties": {"a": {"type": "integer"}}, "additionalProperties": {"type": "number"}}', '{"foo": 1, "a": 2, "b": false}'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"multipleOf": 2}', '4'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"multipleOf": 1.5}', '4.5'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"multipleOf": 4.5}', '2'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"pattern": "a"}', '"a"'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"pattern": "[Ss]mith"}', '"My blacksmith produces excellent steel"'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"pattern": "[Ss]mith"}', '"I am no good at smitking, I''m afraid"'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"maxItems": 5}', '[1, 2, 3, 4]'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"maxItems": 2}', '[1, 2, 3, 4]'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"minItems": 1}', '[1, {"bc": 2}, 3, 4]'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"minItems": 5}', '[{"a": 1}, 2, 3, 4]'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"maxProperties": 4}', '"dab"'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"maxProperties": 4}', '{"a": 1, "b": 4, "c": 4, "d": 67, "e": 91}'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"minProperties": 4}', '{"a": 1, "b": 4, "c": 4, "d": 67, "e": 91}'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"minProperties": 6}', '{"a": 1, "b": 4, "c": 4, "d": 67, "e": 91}'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"anyOf": [{"type": "number"}, {"type": "integer"}]}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"allOf": [{"type": "number"}, {"type": "integer"}]}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"oneOf": [{"type": "number"}, {"type": "integer"}]}', '2'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"minimum": 3}', '2'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"minimum": 1}', '2'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"uniqueItems": true}', '[1, 2, 3]'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"uniqueItems": false}', '[1, 2, 2]'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"uniqueItems": true}', '[1, 2, 2]'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"uniqueItems": true}', '[1, {"a": {"b": 1}}, {"a": {"b": 1}}]'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"uniqueItems": true}', '[1, {"a": {"b": 1}}, {"a": {"b": 2}}]'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"minimum": 2}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"minimum": 2, "exclusiveMinimum": true}', '2'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"maximum": 3}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"maximum": 1}', '2'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"maximum": 2}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"maximum": 2, "exclusiveMaximum": true}', '2'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"type": "integer"}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"type": ["integer"]}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"type": ["string", "integer"]}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"type": ["string", ["integer", "string"]]}', '2'); ERROR: type elements must be strings or objects SELECT is_jsonb_valid('{"type": ["null", "string"]}', '2'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"type": ["null", {"type": "integer"}]}', '2'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"type": "integer"}', '2.5'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"properties": {}}', '2.5'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"type": "null"}}}', '{"a": 1}'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"type": "integer"}}, "additionalProperties": false}', '{"a": 1, "b": 5}'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"type": "integer"}}, "additionalProperties": true}', '{"a": 1, "b": 5}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"type": "integer"}}, "additionalProperties": {"type": "boolean"}}', '{"a": 1, "b": 5}'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"type": "integer"}}, "additionalProperties": {"type": "number"}}', '{"a": 1, "b": 5}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"type": "number"}}}', '{"a": 2.5}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"type": "integer"}}}', '{"a": 2}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"type": "integer"}}}', '{"a": 2.5}'); is_jsonb_valid ---------------- f (1 row) --- property is compared with length of key, in this case 4 SELECT is_jsonb_valid('{"properties": {"a": {"type": "inte"}}}', '{"a": 2}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"required": true}}}', '{}'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"required": false}}}', '{}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"required": true}}}', '{"a": 1}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"required": ["a", "b"]}', '{"a": 1}'); is_jsonb_valid ---------------- f (1 row) SELECT is_jsonb_valid('{"required": ["a", "b"]}', '{"a": 1, "b": 2}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"required": ["a", "b"]}', '1'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"items": [{"type": "integer"}, {"type": "number"}]}', '[1, 2.5, 3.5]'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"items": {"type": "integer"}}', '[1, 2, 3]'); is_jsonb_valid ---------------- t (1 row) select is_jsonb_valid('{"items": {"type": "integer"}}', '[1, 2, 3.5]'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"items": [{"type": "integer"}, {"type": "number"}], "additionalItems": false}', '[1, 2.5, 3.5]'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"items": [{"type": "integer"}, {"type": "number"}], "additionalItems": {"type": "string"}}', '[1, 2.5, 3.5]'); is_jsonb_valid ---------------- f (1 row) select is_jsonb_valid('{"items": [{"type": "integer"}, {"type": "number"}], "additionalItems": {"type": "number"}}', '[1, 2.5, 3.5]'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"properties": {"a": {"type": "integer"}}}', '{"b": 1}'); is_jsonb_valid ---------------- t (1 row) SELECT is_jsonb_valid('{"type": 1}', '2'); ERROR: type elements must be strings or objects