Free JSON Schema Generator

Paste JSON to automatically generate a JSON Schema.

No data leaves your device

How to Use

  1. Paste a JSON object or array into the Input box.
  2. Toggle options: include "required" arrays or "examples" from your values.
  3. Click Generate Schema to create a JSON Schema (Draft 2020-12).
  4. Copy or Download the generated schema.

Frequently Asked Questions

What JSON Schema version does this generate?

The generator outputs JSON Schema Draft 2020-12 (https://json-schema.org/draft/2020-12/schema), the latest stable draft.

Does it handle nested objects and arrays?

Yes. The generator recursively processes nested objects and arrays. For arrays, it infers the schema from the first element.

Can I edit the generated schema?

The output is a starting point. You may want to add constraints like minLength, minimum, pattern, or enum depending on your needs.

What JSON Schema Is For

JSON Schema is a declarative way to describe what a JSON document should look like: what properties it has, what types those properties hold, what's required vs optional, and what values are valid. It's the JSON-world equivalent of XSD for XML or a database table definition. The official project lives at json-schema.org.

Where you'll meet it in the wild:

The Drafts You'll See in the Wild

JSON Schema's specification has been published as a series of drafts. The current stable draft is 2020-12 (per the official spec page: "The current version is 2020-12"). The drafts you might encounter:

When in doubt, choose the draft that matches your validator. AJV (the most popular JavaScript validator) supports Drafts 04, 06, 07, 2019-09, and 2020-12 with explicit opt-in. jsonschema in Python does the same. If you don't know what your downstream consumer wants, 2020-12 is a safe default for new work.

The Built-in Types

JSON Schema describes seven base types corresponding to JSON's value kinds:

typeJSON valueCommon keywords
string"hello"minLength, maxLength, pattern, format
number42, 3.14minimum, maximum, exclusiveMinimum, multipleOf
integer42Subset of number; no fractional component.
booleantrue / falseNo additional constraints.
nullnullDistinct type; explicit when nulls are valid.
array[…]items, minItems, maxItems, uniqueItems
object{…}properties, required, additionalProperties

Composition keywords let you mix-and-match: oneOf (exactly one), anyOf (at least one), allOf (every one), not (the inverse). Plus enum for a finite list of allowed values and const for a single fixed value.

What an Auto-Generated Schema Can and Can't Tell You

Inferring a schema from a single JSON example is powerful but limited. The generator can detect:

It cannot detect:

Treat the output as a 70%-done starting point. The valuable additions (what fields are actually required, what string formats apply, what value ranges are allowed, what each field means) are the human-curation step.

Two Subtle Pitfalls Worth Knowing

JSON Schema vs Zod / Joi / Yup vs TypeScript Types

Several technologies overlap with JSON Schema's role; each has a different sweet spot:

If your schema needs to be consumed by multiple languages or by tools (IDEs, OpenAPI tooling, code generators), JSON Schema is the right home. If you're staying inside a single language, the language-native option is usually nicer to write.

Common Use Cases

Common Mistakes

  1. Treating the auto-generated schema as the final spec. It's a starting point. Add format hints, mark genuinely-optional fields, add documentation, set value ranges.
  2. Missing the $schema declaration. Validators use it to know which draft to apply. Always include it at the top of the schema.
  3. Treating required as a per-property attribute. Unlike XSD or Mongoose schemas, JSON Schema's required is an array at the parent object level listing the names of required properties.
  4. Forgetting additionalProperties: false when you want strict validation. The default is true, meaning unknown keys are silently allowed.
  5. Confusing enum with examples. enum = the list of allowed values (validation). examples = sample values for documentation only (no validation effect).
  6. Assuming format is enforced. By default in Draft 2020-12 it's an annotation, not an assertion; your email regex won't run unless you opt in.
  7. Inferring optionality from a single example. Every key in your example becomes required by default. Real specs almost always have optional fields; remove them from the required array as part of curation.

More Frequently Asked Questions

Will the schema work with OpenAPI 3.1?

Yes. OpenAPI 3.1 (released February 2021) aligned its schema language fully with JSON Schema Draft 2020-12, which is what this generator emits. Drop the schema into components.schemas in your OpenAPI document and reference it via $ref. Older OpenAPI 3.0 used an earlier subset; you may need to adjust if you're targeting 3.0.

Can I generate types in my language from this schema?

Yes. quicktype generates TypeScript, Go, Python, Java, C#, Swift, Kotlin, Rust, Elm, and others from a JSON Schema. json-schema-to-typescript is a JS-specific alternative. Most modern languages have at least one schema-to-types tool; the generated schema works as input for all of them.

What's the difference between $defs and definitions?

Both are places to put reusable sub-schemas you can $ref elsewhere in the document. definitions is the legacy name, used in Drafts 04, 06, and 07. $defs is the current name, introduced in Draft 2019-09 and continuing in 2020-12. Functionally equivalent, but use $defs for new work.

Is my JSON sent anywhere?

No. Schema generation runs entirely in your browser. The pasted JSON is parsed locally, walked, and emitted as a schema in the output textarea. Nothing is uploaded to a server, logged, or kept after you close the tab. This matters because JSON examples often contain real data (customer records, internal API responses, employee info) that you don't want flowing through a third party.

Why did my array's schema only describe the first element?

Inference from a single example treats arrays as homogeneous: it looks at the first element and assumes the rest match. If your real array can hold different shapes, you'll need to write the items as { "oneOf": [...] } by hand. Or run the generator on each variant separately and combine the schemas.

Should I use a generator at all, or write the schema by hand?

For a small schema you control end-to-end, writing by hand teaches you the spec faster. For a large API response with dozens of nested objects, generating gets you to a draft in seconds and you spend the saved time curating constraints, descriptions, and required arrays. Most working developers do both: generate, then curate.

Related Tools

JSON Formatter JSON Compare JSON to YAML