Why Generate Instead of Write
Writing JSON Schema from scratch for a 200-property API response is tedious and error-prone. Generating a schema from a known-good sample gets you 90% of the way there — you just need to tighten constraints (required, enum, format) afterwards.
How Generation Works
A schema generator walks the sample JSON, infers types from each value, recurses into objects and arrays, and merges differing array element shapes into a oneOf or anyOf. Most generators target Draft 2020-12 by default, with options for Draft-07 for OpenAPI 3.0 compatibility.
Tightening Generated Schemas
Generated schemas are intentionally lax — every property is optional, no enums, no format constraints. After generating, you should: mark required properties, add enum constraints to known string sets, set format: date-time on ISO timestamps, and add minLength/maxLength on bounded strings. See the JSON Schema reference for what each of these keywords actually does.
For OpenAPI Specs
Pass the generated schema through an OpenAPI 3.0 converter (Draft 2020-12 → OpenAPI dialect) before pasting into your spec. Recent Swagger UI versions accept Draft 2020-12 directly under OpenAPI 3.1.
For Contract Testing
Run the generated schema as a Pact-style contract: any sample response should validate against it. New shapes that fail validation indicate a possible breaking change — surface them before merging.
Try It Yourself
Use our companion tool to apply what you read above.