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.
Common Use Cases
- API contract design: generate Schema drafts from real response examples to speed up OpenAPI documentation.
- Gateway validation: intercept non-compliant requests at API Gateway or BFF layers using Schema.
- LLM structured output: create function calling or response_format configs for GPT, Claude, and similar models.
- Frontend-backend alignment: unify request/response format definitions to reduce missing fields and type mismatches.
- Data quality checks: batch-validate logs or imported data against expected structures.
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.
What is the relationship between JSON Schema and OpenAPI?
OpenAPI 3.x request and response bodies are based on a JSON Schema subset. Generated schemas can be embedded directly in OpenAPI docs.
How do I generate structured output config for LLMs?
After generating a schema, the tool provides OpenAI response_format and Anthropic tool snippets you can copy into API calls.
Why can empty arrays not infer item type?
Empty arrays have no elements to analyze. Provide an example with at least one representative element for the tool to infer items type and structure.
Which JSON Schema Draft version is supported?
The tool generates Draft-07 compatible schemas, compatible with AJV and most OpenAPI toolchains.
Will optional fields be marked as required?
Fields present in the example are marked required by default. Remove optional fields from the required array manually.
Can it validate deeply nested JSON?
Yes. AJV supports arbitrarily deep nested objects and arrays; performance is sufficient for typical API responses.