Developer Tools· 5 min read

JSON Schema Generator: Infer Draft-07 Schemas from Samples

You will learn how to generate a valid JSON Schema draft-07 from any sample JSON object, including nested types, required fields, and array unions.

By EasyDevTools Team Last updated: 2026-08-24

Why this matters

JSON Schema is the de facto standard for validating, documenting, and generating forms from JSON data. Without a schema, your API accepts any structure, your documentation is hand-written and inevitably out of date, and your form generators have no type information to work with. A single schema file can power runtime validation in Express middleware, generate TypeScript interfaces via tools like json-schema-to-typescript, and produce interactive documentation in Swagger or Redoc. The upfront investment of writing or generating a schema pays dividends across the entire development lifecycle.

Writing schemas manually is tedious, especially for deeply nested objects with dozens of fields. You need to specify the type of every property, mark which fields are required, define array item schemas, and handle mixed-type arrays. A schema generator that infers all of this from a sample JSON object eliminates the boilerplate. You paste a representative JSON payload, click generate, and receive a draft-07 schema that captures the structure, types, and nesting of your data.

The inference engine handles the most common patterns: objects get type object with a properties block, arrays get type array with an inferred items schema, and numbers without a fractional part are typed as integer rather than number. Mixed-type arrays produce union types in the items schema, which is a more accurate representation than defaulting to a generic type. Every key present in the sample is marked as required, which is a reasonable default for a single-sample inference.

See it in action

Reference table

JSON valueInferred schema type
String`{ "type": "string" }`
Number (no fraction)`{ "type": "integer" }`
Number (with fraction)`{ "type": "number" }`
Boolean`{ "type": "boolean" }`
Null`{ "type": "null" }`
Array`{ "type": "array", "items": ... }`
Object`{ "type": "object", "properties": {...}, "required": [...] }`

How to use it

Paste a representative JSON object into the input area.

Click Generate Schema to produce the draft-07 schema.

Review the output, adjusting required fields or adding format constraints as needed.

Copy the schema and integrate it with your validation layer, documentation generator, or form builder.

Testing your result

After generating the schema, validate it against the original sample using a JSON Schema validator like Ajv. The sample should pass validation without errors. Then test with modified data — remove a required field and confirm the validator flags it, change a string to a number and verify the type check fires. If you have access to multiple representative payloads, run each one through the validator to identify fields that should be optional. A single sample cannot distinguish required from optional fields, so this manual review step is essential for production schemas.

You can also validate the schema itself by running it through a meta-schema validator, which checks that the schema document conforms to the draft-07 specification. Most schema validators like Ajv perform this check automatically when you load the schema. Pay special attention to nested object schemas — verify that the properties and required arrays are correctly nested and that array item schemas match the actual element types in your sample. If your sample contains an array with different object shapes, confirm the generated union type covers all observed variants.

For a final check, use the generated schema to produce TypeScript interfaces with a tool like json-schema-to-typescript and compare the output types against what you expected. This end-to-end test catches issues like properties being typed as string when they should have format constraints, or required arrays containing fields that are actually optional in practice. The schema is a starting point, not a finished product — treat it as a first draft that needs human review and refinement.

Common mistakes

Assuming all fields marked required are truly mandatory — the generator marks every key as required because it only sees one sample.

Forgetting to add format constraints like `format: email` or `format: date-time` that the generator cannot infer from a plain string value.

Using the generated schema directly in production without validating it against edge-case payloads your API might receive.

Edge cases and options

Mixed-type arrays, where one element is a string and another is a number, produce a union items schema that accepts multiple types. This is more useful than defaulting to an empty schema but less precise than what you would write by hand for a well-defined API. Empty arrays in the sample produce a generic items schema since there are no elements to infer from. Nested objects are handled recursively, so payloads several levels deep produce correctly nested schema definitions. The `$schema` field is set to draft-07 for compatibility with the widest range of validators and tooling.

Real-world use cases

A backend developer generating a validation schema from a sample API response to plug into Express middleware with Ajv.

A technical writer creating JSON Schema documentation from example payloads without writing schemas manually.

A front-end developer bootstrapping form generation from a sample object using a library that consumes JSON Schema.

Frequently asked questions

Q: Which draft version is used?

A: Draft-07, the most widely supported version. The $schema field is included for compatibility with validators.


Q: How are required fields determined?

A: Any key present in the sample is treated as required. To mark fields optional, you would need to inspect multiple samples — that is beyond this tool's scope.


Q: What about integer vs number?

A: If a JSON number has no fractional part, the schema says integer; otherwise number.


Q: Can it handle arrays of objects?

A: Yes — the items schema is inferred from the first array element. Mixed arrays produce union types in the items definition.


Q: Does it support additionalProperties or patternProperties?

A: The generated schema uses standard properties and required. You would need to add additionalProperties, patternProperties, or enum constraints manually after generation.

Start using it now

Try the JSON Schema Generator tool. See also JSON to TypeScript, JSON Formatter, and JSON to CSV.

Need help using this tool?

Read our complete JSON Schema Generator tutorial for step-by-step guidance.

Ready to try the tool?

No accounts. No uploads. No limits. Start now.