Generate JSON Schema from examples carefully
Infer useful types and required fields without mistaking observations for guarantees.
7 minute read · Updated August 2026Infer a schema locally →One payload shows possibility, not optionality
Every property in one object is present by definition, but that does not prove it is required. Multiple representative samples let an inference engine distinguish always-present fields from intermittent ones.
Conflicting samples should become unions
If an identifier appears as both an integer and a string, hiding that conflict produces a brittle schema. An anyOf union records what was observed and gives you a place to make a deliberate contract decision.
{
"anyOf": [
{ "type": "integer" },
{ "type": "string" }
]
}Review formats and enums
Email, date, URI, and UUID formats can be inferred from strings, but they remain hypotheses. Enum inference should require repeated values and a conservative cardinality limit.