JSON Schema Generator
Automatically generate standards-compliant JSON Schema definitions from JSON data
// JSON Schema will be generated automaticallyWhat is JSON Schema?
JSON Schema is a specification for describing and validating JSON data structures. It defines rules for structure, data types, constraints, and is widely used for API validation, form validation, config file verification, and more.
With JSON Schema, you can:
- Data Validation: Verify JSON data matches expected format and constraints
- Documentation Generation: Auto-generate API docs and type definitions
- Code Intelligence: Get smart completion and type checking in IDEs
- Automated Testing: Auto-validate response data format in tests
This tool supports JSON Schema Draft-07 specification, intelligently inferring nested objects, array types, enum values, and other complex structures to help you quickly create standardized Schema definitions.
How to Use
How to use
- Paste JSON data in the left input box, or click Sample to load example data
- Configure options: set Schema ID, choose whether all fields are required, add default values, etc.
- The corresponding JSON Schema definition is generated automatically on the right
- Click Copy to copy the generated Schema to clipboard
- Use the Schema for API validation, form validation, or config file verification
Schema Tips
- Generated schemas reflect the sample JSON you provide, so include representative optional fields, null values, arrays, and edge cases before copying the result.
- Review required fields and numeric/string formats manually; sample-based inference cannot always know your business rules.
Use Cases
Technical Principle
JSON Schema is a declarative vocabulary for annotating and validating JSON documents, defined across multiple IETF drafts (Draft 4 / 6 / 7 / 2019-09 / 2020-12). The latest is Draft 2020-12, which defines seven primitive types (string, number, integer, boolean, array, object, null), an open-ended format vocabulary (email, uri, date-time, uuid, ipv4, hostname, ...), and dozens of constraint keywords: pattern (regex), minimum/maximum/exclusiveMinimum/exclusiveMaximum (number range), minLength/maxLength (string length), minItems/maxItems/uniqueItems (array constraints), required (object-level required array), additionalProperties (whether extra fields are allowed), enum and const (allowed values), and $ref (subschema reuse). The page generates Draft 2020-12 output by default, with the older Draft-07 (still the most common in production schemas) selectable from the dropdown. The generator's inference is a single pass over the user-supplied JSON, building a schema object recursively. The map at the heart of the inference is: integer (Number.isInteger and no fractional part) -> {type: 'integer'}, float -> {type: 'number'}, string -> {type: 'string'}, boolean -> {type: 'boolean'}, array -> {type: 'array', items: <recurse on the first element>} or {type: 'array', prefixItems: [...]} for tuples in Draft 2020-12, object -> {type: 'object', properties: <recurse on each key>}, null -> {type: 'null'}. For arrays of mixed element types the generator emits a oneOf subschema covering each observed type. For multiple sample objects, the generator compares them to assemble the required list: a key is required if it appears in every sample, optional if any sample omits it. Patterns and constraints are inferred when samples cluster: if all numbers in a field fall in [1, 100], the generator emits {type: 'integer', minimum: 1, maximum: 100}; if a string field is always a UUID, the generator tags it with format: 'uuid' and emits a pattern: '^[0-9a-f]{8}-...' regex. The enum heuristic fires when a string field takes ≤10 distinct values across the samples (e.g. role: 'admin' | 'editor' | 'viewer' all observed), in which case the generator emits an enum array. Deeply nested objects and recursive structures are extracted into a $defs section (Draft 2020-12; the older $definitions is the Draft-07 keyword) and referenced via $ref. Recursive structures — e.g. a tree node with a 'children' field of type tree node — get a stub $ref pointing to the parent's $defs entry, which the validator resolves at validation time. The generator picks the right ref-vs-inline trade-off automatically: shallow schemas stay inline, deep ones get broken into definitions to keep the output readable. Generated schemas are deterministic for a given input: the same JSON samples always produce the same schema, and the generator is implemented in pure JavaScript with no remote calls.
- Type inference rules: integer numbers -> integer, floating-point -> number, strings -> string, booleans -> boolean, arrays -> array + items, objects -> object + properties. JSON null -> type: null (Draft 6+) or type: 'null' string.
- Required field detection: comparing all sample objects, fields present in every object are treated as required and added to the required array; missing ones are optional. Single-sample input leaves required: [] since the heuristic needs at least two samples.
- Enum inference heuristic: when a field takes a small finite set of distinct string values across samples (cardinality <= 10), it is auto-recognised as an enum constraint. Larger cardinalities stay as plain string type.
- Auto-detected format: based on string signatures, fields are tagged with format hints like email, uri, date-time, uuid for documentation and validation. The format keyword is informational in Draft 2020-12 - validators can choose to enforce or ignore it.
- Nested $ref extraction: deeply nested objects are extracted into internal $defs (Draft 2020-12 keyword; the older $definitions is from Draft 7) and referenced via $ref, keeping the Schema from getting too verbose. Recursive structures get a stub $ref pointing to the parent's $defs entry.
- Constraint expansion: beyond basic types, you can also add minimum/maximum (number range), minLength/maxLength (string length), pattern (regex), and similar constraints. The generator emits these when input samples cluster on specific values.
- Draft selection: 2020-12 (the latest) is the default and uses $defs; 2019-09 uses $defs as well; Draft-07 uses $definitions and is what most existing tools still emit. Draft 6 introduced strict-required semantics where required fields are listed in the parent's required array rather than as a sibling property.
- Composition keywords (Draft 2019-09+): allOf (must match all subschemas), anyOf (at least one), oneOf (exactly one), not (must not match). The generator picks oneOf when sample values fit two disjoint subschemas (e.g. integer vs string).
Examples
Simple Object -> Schema
{"name": "Alice", "age": 25}
->
{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"required": ["name", "age"]
}Schema with Array
{"tags": ["js", "ts"]}
->
{
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": { "type": "string" }
}
}
}Schema with Enum
{"role": "admin"}
->
{
"type": "object",
"properties": {
"role": { "type": "string", "enum": ["admin", "user", "guest"] }
}
}FAQ
What is JSON Schema?
JSON Schema (currently 2020-12 draft) is a vocabulary for validating JSON documents. It describes a document's expected shape - which fields exist, their types, ranges, and patterns - similar to XML Schema or TypeScript types. Tools like Ajv, Hyperjump, and most API frameworks consume it for runtime validation.
Which JSON Schema draft does the generator output?
Modern drafts (typically 2020-12 or draft-07). The output starts with $schema declaring the version, $id where applicable, type, and the appropriate keywords for objects, arrays, strings, numbers, booleans, null. Switch the draft option if your validator requires a specific older version.
How does it infer types from a JSON sample?
It walks the sample, recording each property's type. For arrays, it infers the items schema from one or more elements (taking the union if elements differ). For mixed-type properties, it uses oneOf or anyOf. The result is a permissive starting schema; tighten constraints (required, minLength, pattern) by hand.
Are all properties marked as required?
Configurable. The default is to mark every observed property as required. Toggle 'all optional' if your sample is just one example and other instances may legitimately omit fields. You can edit the required array after generation.
How are nested objects and arrays handled?
Nested objects become nested 'properties' blocks; arrays become 'items' definitions. Deep nesting works fine. If the same shape appears repeatedly, you can refactor with $defs / $ref afterwards - the generator does not auto-deduplicate.
What can't this generator infer from samples?
Format constraints (date-time, email, uuid), enum membership, regex patterns, minimum/maximum, minItems/maxItems, and dependencies need to be added by hand because a single sample doesn't show them. Use the generated schema as a skeleton, then tighten it.
Is my JSON uploaded?
No. Inference runs locally. Pasted JSON does not leave your browser.