JSON Schema Generator
Generate JSON Schema from sample data. Paste a JSON example to create a schema:
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
- Paste sample JSON — Provide a representative example
- Configure options — Set title, required fields, format detection
- Generate — Get a JSON Schema (draft 2020-12)
- 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 Value | Schema 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.comuri— https://example.comdate-time— 2024-01-15T10:30:00Zdate— 2024-01-15time— 10:30:00uuid— 550e8400-e29b-41d4-a716-446655440000ipv4— 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
- JSON Schema Validator — Validate JSON against schema
- JSON Validator — Basic JSON validation
- JSON to TypeScript — Generate TS interfaces
- JSON to Python — Generate Python dataclasses
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.