{}JSONLint.app

JSON Schema Generator

Generate JSON Schema from sample data. Paste a JSON example to create a schema:

Loading...
Loading...

What is JSON Schema?

JSON Schema is a vocabulary that allows you to validate, annotate, and describe JSON data. It defines the structure, types, and constraints that JSON documents must follow.

This tool analyzes your sample JSON and generates a schema that matches its structure. You can then use this schema to validate other JSON documents.

How It Works

  1. Paste sample JSON — Provide a representative example
  2. Configure options — Set title, required fields, format detection
  3. Generate — Get a JSON Schema (draft 2020-12)
  4. Validate — Use the schema to validate other data

Generated Schema Features

Type inference

The generator detects JSON types and maps them to schema types:

JSON ValueSchema Type
"hello""type": "string"
42"type": "integer"
3.14"type": "number"
true"type": "boolean"
null"type": "null"
[...]"type": "array"
{...}"type": "object"

Format detection

When enabled, the generator recognizes common string formats:

  • email — user@example.com
  • uri — https://example.com
  • date-time — 2024-01-15T10:30:00Z
  • date — 2024-01-15
  • time — 10:30:00
  • uuid — 550e8400-e29b-41d4-a716-446655440000
  • ipv4 — 192.168.1.1

Example

From this JSON:

{
  "name": "John",
  "email": "john@example.com",
  "age": 30
}

Generates this schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Generated Schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "email": { "type": "string", "format": "email" },
    "age": { "type": "integer" }
  },
  "required": ["name", "email", "age"]
}

Options Explained

Mark all required

When enabled, all non-null properties are added to the required array. Disable this for schemas where most fields are optional.

Detect formats

Automatically adds format keywords for recognized patterns like emails and dates. Validators can use these for stricter validation.

Include examples

Adds examples arrays with values from your sample data. Useful for documentation and API specifications.

Using the Generated Schema

Validate with our tool

Copy the schema and paste it into our JSON Schema Validator to validate other JSON documents.

JavaScript validation

import Ajv from 'ajv';

const ajv = new Ajv();
const validate = ajv.compile(schema);

const valid = validate(data);
if (!valid) console.log(validate.errors);

Python validation

from jsonschema import validate, ValidationError

try:
    validate(instance=data, schema=schema)
except ValidationError as e:
    print(e.message)

Limitations

  • Single sample — Schema is based on one example; edge cases may not be covered
  • No constraints — Doesn't infer min/max, patterns, or enums
  • Array type from first element — Mixed-type arrays need manual adjustment

After generating, review and enhance the schema with additional constraints based on your requirements.

Related Tools

Frequently Asked Questions

What JSON Schema version is generated?

The generator outputs JSON Schema draft 2020-12, the latest version. It's compatible with most modern validators.

How do I add custom validation rules?

Edit the generated schema manually. Add minimum, maximum,pattern, enum, or other constraints as needed.

Can I generate from multiple samples?

Currently, the generator uses a single sample. For complex schemas with optional fields, create a sample that includes all possible fields, then manually mark optional ones.

Common Mistakes & Pro Tips

  • Generated schemas are a starting pointInference can only describe the one sample you gave it. It cannot know which fields are truly required, what the allowed enum values are, or what string formats apply. Treat the output as a scaffold and hand-tune it before using it for real validation.
  • Required vs optional is a guessFrom a single example the generator typically marks every present field as required (or, alternately, none). If your real data has optional fields, edit the "required" array; feeding multiple representative samples, where supported, gives a better picture of which keys are always present.
  • Arrays are inferred from element samplesThe element schema is derived from the items present in your sample array. An empty array yields no item constraints, and a heterogeneous array may collapse to a loose type or an "anyOf". Verify the inferred "items" schema covers every variant your data can actually contain.
  • No enums, patterns, or ranges by defaultInference produces broad types like "string" or "number" without "enum", "pattern", "minimum", or "format". A status field becomes a plain string, not an enum of allowed values. Add these constraints manually to make the schema actually enforce your business rules.
  • Null values widen the typeIf a sampled field is null, the generator may infer "type": "null" or omit a useful type, which then rejects real non-null values. Decide whether the field is nullable and, if so, use a union like "type": ["string", "null"] rather than leaving it as null-only.

Frequently Asked Questions

How accurate is an inferred schema?

It accurately describes the structure of the sample you provided, but it cannot infer intent. It will not know your real required fields, enums, value ranges, or string formats, and it can under-constrain (everything optional) or over-constrain (everything required). Always review and edit the output before relying on it.

How do I turn a string field into an enum?

Find the property in the generated schema and replace its "type": "string" with an "enum" array of the allowed values, for example "enum": ["active", "inactive", "pending"]. You can keep "type": "string" alongside "enum" for clarity. The generator will never produce enums on its own because it cannot know the full value set from a sample.

Which draft does the generated schema target?

The output includes a "$schema" declaration for the draft it targets, commonly draft-07 or 2020-12. If you need a different dialect, change the "$schema" value and adjust any version-specific keywords, such as switching between an array-form "items" (draft-07 tuples) and "prefixItems" (2020-12).

Can I generate a schema from multiple examples?

Generating from a single document only captures that document's shape. If you have several representative samples, the most reliable approach is to generate from each and then merge them by hand, widening types and relaxing "required" so the schema accepts every valid variant. This catches optional fields and mixed types that one sample would miss.

Why are nested objects fully expanded instead of using $ref?

Basic inference expands each object inline rather than factoring repeated shapes into reusable "$defs" with "$ref". If the same structure appears in many places, refactor it into a single definition and reference it, which keeps the schema DRY and easier to maintain. This is a manual step after generation.

Is my sample JSON sent to a server?

No. The schema is inferred locally in your browser, so your sample data never leaves your device. You can safely paste production payloads to scaffold a schema without exposing them.