← All JSON guides

JSON guide · 7 min read

How to Generate a JSON Schema from Sample JSON

Infer a JSON Schema from example data, then strengthen required fields, formats and validation rules manually.

Published 2026-08-05Reviewed 2026-08-05

What schema inference can determine

A generator can observe object properties, arrays and primitive value types in the supplied example. It can create a fast starting point for documentation and validation.

What one sample cannot prove

One example cannot reliably determine whether a field is optional, which string format is intended, the full range of allowed values or whether an array may contain other shapes.

  • Review required fields.
  • Add minimum and maximum constraints.
  • Add enums only when the domain guarantees them.
  • Describe nullable and optional behavior explicitly.

Generate, review and validate

Generate the draft schema, edit it to reflect the actual contract, then validate several valid and invalid examples. Include edge cases rather than relying only on the original sample.

Common questions

Frequently asked questions

Can a schema generator infer required fields?

It can mark observed fields as required, but only domain knowledge can confirm whether they are always required.

Should generated schemas be used unchanged?

No. Treat them as drafts and review them against real requirements and additional examples.