ToolActToolAct

JSON Schema Generator

Automatically generate standards-compliant JSON Schema definitions from JSON data

JSON Input
Lines: 1 | Characters: 0
JSON Schema Output
// JSON Schema will be generated automatically
Properties: 0 | Lines: 1

Configuration Options

Schema ID
Set a unique identifier for the Schema, typically in URI format, used for referencing and identifying Schema in large systems
All Fields Required
When enabled, all properties are added to the required array, meaning these fields must exist in the data
Add Default Values
Auto-generate default property based on actual values in sample JSON, useful for config files needing defaults
Add Field Descriptions
Auto-add description field for each property, describing data type and source, helpful for documentation
Strict Mode
Enable additionalProperties: false to prohibit undefined extra properties, ensuring strict data structure consistency

What 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

  1. Paste JSON data in the left input box, or click Sample to load example data
  2. Configure options: set Schema ID, choose whether all fields are required, add default values, etc.
  3. The corresponding JSON Schema definition is generated automatically on the right
  4. Click Copy to copy the generated Schema to clipboard
  5. 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

Draft schemas from real API samplesPaste a representative JSON response and generate a draft-07 schema that captures object properties, primitive types, nested arrays, defaults, and required fields. It gives backend and frontend teams a concrete starting point before they tighten edge cases by hand. A real sample beats guessing because required-vs-optional and enum membership are inferred from what actually shows up in the data.
Document configuration filesFor internal config examples, enable defaults and descriptions to produce a schema that is useful in editors and documentation. Strict mode can add additionalProperties: false, which makes accidental keys easier to catch once the schema is wired into validation. Pair the schema with a CI check that fails when a config file no longer matches its contract.
Explore data shape before validation workThe generator reports the property count and infers arrays from sample items, helping you see the rough breadth of a payload quickly. It is especially practical for first-pass schema authoring where a live sample exists but a formal contract has not been written yet. Once the shape is mapped, hand the schema to a type generator for a stronger typed binding.
Tighten inferred types with nullable and required hintsUse the strict and nullable options so the generated draft-07 schema marks optional fields correctly instead of assuming every key is always present. Review the resulting required array by hand, since one missing sample value can hide a field that is actually mandatory on the server. Toggle nullable handling separately from required so a field that allows null but is still expected can be modeled accurately.
Distinguish draft-07 vs 2020-12 and enum inferenceThis generator emits JSON Schema draft-07 by default, which is still the most widely supported across Ajv, jsonschema, and form libraries; newer projects may want to manually upgrade to 2020-12 to use if/then/else, prefixItems, or the const keyword. Enum inference is heuristic-driven: when a string field has fewer than ~10 distinct values across the sample, it is auto-promoted to an enum, so double-check a field like status that should stay free-form. Treat the generated draft-07 schema as a starting draft, then convert to 2020-12 with a transformer if the consumer library supports it.

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.