2026-09-27 · 6 min read · Rahul Chitturi
- json-schema
- validation
- regex
JSON Schema can validate object members whose names are not known in advance. propertyNames constrains each name, while patternProperties selects value schemas with regular expressions. A property can match several patterns, and every matching schema must succeed.
Unexpected failures usually come from unanchored expressions, overlapping patterns, or the mistaken belief that patternProperties consumes names so additionalProperties no longer matters.
List every schema that reaches the property
Record the schema dialect, exact property name, its value, all matching patterns, declarations in properties, and the additionalProperties or unevaluatedProperties rule. Test regular expressions with the validator's supported syntax rather than a language-specific replacement.
- Anchor patterns when the whole name must match.
- Assume patterns are not implicitly anchored.
- Apply every matching pattern, not the first one.
- Keep name rules separate from value rules.
Reduce overlaps deliberately
Start with one property and one pattern, then add patterns until the failure returns. If overlapping namespaces are intentional, make their combined constraints compatible and document that intersection with a fixture.
Remember that propertyNames validates names but does not mark their values as handled by additionalProperties. Define properties or patternProperties for allowed values, or choose the appropriate unevaluatedProperties design for the pinned dialect.
Build a property-name matrix
Use Flashman's JSON formatter for schemas and instances, regex tester for public name examples, diff for validator output, and YAML/JSON converter for configuration copies.
Test exact prefixes, near misses, empty names, Unicode, case changes, names matching two patterns, declared properties that also match, invalid values, additional names, composed schemas, draft upgrades, and every production validator.