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.