-- patternProperties validates properties matching a regex -- a single valid match is valid SELECT is_jsonb_valid('{"patternProperties":{"f.*o":{"type":"integer"}}}', '{"foo":1}'); is_jsonb_valid ---------------- t (1 row) -- multiple valid matches is valid SELECT is_jsonb_valid('{"patternProperties":{"f.*o":{"type":"integer"}}}', '{"foo":1,"foooooo":2}'); is_jsonb_valid ---------------- t (1 row) -- a single invalid match is invalid SELECT is_jsonb_valid('{"patternProperties":{"f.*o":{"type":"integer"}}}', '{"foo":"bar","fooooo":2}'); is_jsonb_valid ---------------- f (1 row) -- multiple invalid matches is invalid SELECT is_jsonb_valid('{"patternProperties":{"f.*o":{"type":"integer"}}}', '{"foo":"bar","foooooo":"baz"}'); is_jsonb_valid ---------------- f (1 row) -- ignores arrays SELECT is_jsonb_valid('{"patternProperties":{"f.*o":{"type":"integer"}}}', '[]'); is_jsonb_valid ---------------- t (1 row) -- ignores strings SELECT is_jsonb_valid('{"patternProperties":{"f.*o":{"type":"integer"}}}', '""'); is_jsonb_valid ---------------- t (1 row) -- ignores other non-objects SELECT is_jsonb_valid('{"patternProperties":{"f.*o":{"type":"integer"}}}', '12'); is_jsonb_valid ---------------- t (1 row) -- multiple simultaneous patternProperties are validated -- a single valid match is valid SELECT is_jsonb_valid('{"patternProperties":{"a*":{"type":"integer"},"aaa*":{"maximum":20}}}', '{"a":21}'); is_jsonb_valid ---------------- t (1 row) -- a simultaneous match is valid SELECT is_jsonb_valid('{"patternProperties":{"a*":{"type":"integer"},"aaa*":{"maximum":20}}}', '{"aaaa":18}'); is_jsonb_valid ---------------- t (1 row) -- multiple matches is valid SELECT is_jsonb_valid('{"patternProperties":{"a*":{"type":"integer"},"aaa*":{"maximum":20}}}', '{"a":21,"aaaa":18}'); is_jsonb_valid ---------------- t (1 row) -- an invalid due to one is invalid SELECT is_jsonb_valid('{"patternProperties":{"a*":{"type":"integer"},"aaa*":{"maximum":20}}}', '{"a":"bar"}'); is_jsonb_valid ---------------- f (1 row) -- an invalid due to the other is invalid SELECT is_jsonb_valid('{"patternProperties":{"a*":{"type":"integer"},"aaa*":{"maximum":20}}}', '{"aaaa":31}'); is_jsonb_valid ---------------- f (1 row) -- an invalid due to both is invalid SELECT is_jsonb_valid('{"patternProperties":{"a*":{"type":"integer"},"aaa*":{"maximum":20}}}', '{"aaa":"foo","aaaa":31}'); is_jsonb_valid ---------------- f (1 row) -- regexes are not anchored by default and are case sensitive -- non recognized members are ignored SELECT is_jsonb_valid('{"patternProperties":{"[0-9]{2,}":{"type":"boolean"},"X_":{"type":"string"}}}', '{"answer 1":"42"}'); is_jsonb_valid ---------------- t (1 row) -- recognized members are accounted for SELECT is_jsonb_valid('{"patternProperties":{"[0-9]{2,}":{"type":"boolean"},"X_":{"type":"string"}}}', '{"a31b":null}'); is_jsonb_valid ---------------- f (1 row) -- regexes are case sensitive SELECT is_jsonb_valid('{"patternProperties":{"[0-9]{2,}":{"type":"boolean"},"X_":{"type":"string"}}}', '{"a_x_3":3}'); is_jsonb_valid ---------------- t (1 row) -- regexes are case sensitive, 2 SELECT is_jsonb_valid('{"patternProperties":{"[0-9]{2,}":{"type":"boolean"},"X_":{"type":"string"}}}', '{"a_X_3":3}'); is_jsonb_valid ---------------- f (1 row)