JSON Schema Generator

Paste any JSON object or array and get a JSON Schema (Draft 2020-12) describing its structure. The generator infers types, marks every present field as required, handles nested objects and arrays of objects by merging properties across items, and produces a schema you can hand-edit further or wire straight into a validator like Ajv, jsonschema, or any IDE that supports schema-driven autocompletion. Everything runs in your browser.


      

How to Use This Tool

  1. Paste your JSON sample into the input area — an object, an array of objects, or any nested combination. The richer the sample, the more accurate the inferred schema.
  2. Click Generate Schema to infer a JSON Schema (Draft 2020-12) describing the input's structure, types, and required fields.
  3. Review the output — every field present in the sample is marked required by default. Hand-edit to add formats (email, date), tighten constraints, or relax requirements as needed.
  4. Copy or download the schema and reference it from your validator (Ajv, jsonschema, etc.) or your IDE's JSON Schema config.

What Is JSON Schema?

JSON Schema is a JSON-based vocabulary for declaring what JSON data should look like. A schema document specifies which keys are required, what types each key's value must be, what values are allowed, and how nested objects and arrays are structured. Every major language has at least one mature validator that accepts the same schema, which makes JSON Schema the closest thing to a universal validation contract in the JSON world.

The two common ways to get a schema: write one by hand against the spec, or infer one from a real sample of data. Hand-writing is precise but slow and easy to get wrong on edge cases. Inferring from a sample is fast and gets you 90% of the way there — the inferred schema captures every type, required field, and nested structure the sample shows. The remaining 10% is hand-editing: adding format constraints (email, date-time, uuid), value ranges (minimum, maximum), enum lists, regex patterns, and conditional rules that the sample alone can't reveal.

JSON Schema's biggest practical wins are in API design (clients and servers agree on the shape of every request and response), config validation (catch typos in YAML/JSON config files at startup, not at runtime), and IDE support (live autocompletion as you type a config or fixture). It's worth writing the schema even when validation isn't strictly required — the schema document itself becomes lightweight, language-independent documentation.

Frequently Asked Questions

What is a JSON Schema?
JSON Schema is a vocabulary for describing the structure and constraints of JSON data — what fields must be present, what types they have, what values are allowed, what nested structures look like. It's the JSON equivalent of an XSD for XML or a database schema for relational data. Validators in every major language (Ajv for JavaScript, jsonschema for Python, justify for Go, etc.) accept the same schema document, which means one schema definition can drive validation, code generation, IDE autocompletion, and API documentation simultaneously.
What JSON Schema draft does this tool produce?
Draft 2020-12 (the current released spec) by default. The output includes the standard $schema declaration so any validator can identify which draft to apply. The schema is forward-compatible with Draft 2019-09 in most cases — the differences mostly affect dynamic references and conditional schemas, neither of which the inferrer emits. Older drafts (Draft 7, Draft 6, Draft 4) require minor adjustments: change the $schema URL, replace $defs with definitions, and remove prefixItems if you used it.
How does the generator handle arrays of mixed objects?
When an array contains multiple objects, the inferrer merges all the keys it sees across items. Every key that appears in at least one object becomes a property; every key that appears in every object becomes required. Differing types for the same key are combined with oneOf. So an array like [{"a": 1}, {"a": "x", "b": true}] produces a schema with properties a (oneOf integer or string, required) and b (boolean, optional). For strict per-item shapes, hand-edit the generated schema or use a tuple validation with prefixItems.
Can the generator detect formats like email, date, or UUID?
Not automatically — the inferrer looks at JSON types (string, number, boolean, etc.) but doesn't try to guess what kind of string a value is. To add format constraints, hand-edit the generated schema and add "format": "email", "format": "date-time", "format": "uuid", or any other standard format keyword. Most JSON Schema validators treat formats as advisory by default; pass strict-format options to enforce them at validation time.
How do I use the generated schema to validate JSON?
In JavaScript, install Ajv and call ajv.compile(schema)(data) — it returns a boolean and populates compile.errors with details. In Python, install jsonschema and call jsonschema.validate(data, schema). Most modern IDEs (VS Code, JetBrains) accept a $schema URL or path inline and provide live autocompletion and validation as you type. The tool's output is a complete, standalone schema you can save to a file and reference.