JSON Schema & structured output helpers
Infer a draft JSON Schema from one example, validate JSON with AJV, and copy snippets for OpenAI tools or response_format.
Draft only — always review before production.
JSON Schema Generation, Validation, and LLM Output Guide
JSON Schema powers API contracts, OpenAPI docs, gateway validation, and structured LLM output. Inferring a draft from a real example and then tightening rules is usually safer than starting from an empty file.
FormaX infers type, required, object, and array structures, then validates instances with AJV. You still need to add business rules such as enum, format, minimum, and pattern.
From Example to Usable Schema
- Copy a real successful response and remove sensitive fields.
- Generate a draft schema and review whether required fields match the business contract.
- Add format, pattern, or range constraints for IDs, emails, dates, and amounts.
- Validate missing fields, wrong types, and edge cases before publishing to OpenAPI or LLM configs.
Good Example JSON
{"id":1001,"email":"user@example.com","plan":"pro","active":true}Inference Does Not Decide Business Rules
- One example only proves the current value type, not every possible value.
- Empty arrays cannot reveal item type, so include at least one representative element.
- For LLM structured output, add descriptions to reduce wrong field filling.
FAQ
Can I ship the generated schema directly?
Treat it as a draft. Add enums, formats, ranges, and compatibility rules before production.
Why validate with AJV after generating?
AJV simulates runtime pass/fail behavior and reveals mismatches between docs and real payloads.