Online JSON Schema Generator: Auto-Generate Schema from JSON Data
What Is JSON Schema
JSON Schema is a standard for describing and validating JSON data structures. It defines the properties, types, constraints, and defaults of JSON objects. Feed your sample data into our JSON Schema Generator to produce a ready-to-use schema automatically.
Example JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 1 },
"age": { "type": "integer", "minimum": 0 },
"email": { "type": "string", "format": "email" },
"tags": { "type": "array", "items": { "type": "string" } }
},
"required": ["name", "email"]
}
Why You Need JSON Schema
- API documentation: Auto-generate API request/response structure docs
- Data validation: Validate JSON data correctness at runtime
- Form generation: Auto-generate form UI from Schema
- Mock data: Generate test data based on Schema
- Type safety: Generate TypeScript type definitions from Schema
- Config validation: Verify config file format is correct
JSON Schema Core Keywords
| Keyword | Description | Example |
|---------|-------------|---------|
| type | Data type | "string", "number", "boolean", "array", "object" |
| properties | Object properties | { "name": { "type": "string" } } |
| required | Required fields | ["name", "email"] |
| minimum/maximum | Number range | "minimum": 0, "maximum": 100 |
| minLength/maxLength | String length | "minLength": 1, "maxLength": 255 |
| enum | Enum values | ["active", "inactive", "pending"] |
| format | Format validation | "email", "uri", "date-time" |
| items | Array element type | { "type": "string" } |
How to Use an Online Tool
Using ToolVault's JSON Schema Generator:
- Paste a JSON object example
- The tool auto-analyzes the data structure
- Generates complete JSON Schema
- Supports custom constraints (required, ranges, etc.)
- One-click copy Schema code
Auto-Generate from JSON Example
Input
{
"id": 1,
"name": "Alice",
"email": "alice@example.com",
"isActive": true,
"tags": ["developer", "admin"],
"address": { "city": "Shanghai", "zip": "200000" }
}
Output Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"email": { "type": "string" },
"isActive": { "type": "boolean" },
"tags": { "type": "array", "items": { "type": "string" } },
"address": {
"type": "object",
"properties": {
"city": { "type": "string" },
"zip": { "type": "string" }
}
}
}
}
JSON Schema Validation in Code
JavaScript (Ajv)
const Ajv = require('ajv');
const ajv = new Ajv();
const schema = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1 },
age: { type: 'integer', minimum: 0 }
},
required: ['name']
};
const validate = ajv.compile(schema);
const valid = validate({ name: 'Alice', age: 28 });
console.log(valid); // true
Python
from jsonschema import validate, ValidationError
schema = {
"type": "object",
"properties": {
"name": {"type": "string", "minLength": 1},
"age": {"type": "integer", "minimum": 0}
},
"required": ["name"]
}
try:
validate(instance={"name": "Alice", "age": 28}, schema=schema)
print("Validation passed")
except ValidationError as e:
print(f"Validation failed: {e.message}")
FAQ
What JSON Schema Versions Are Supported?
Draft 7 (2018-02) and 2020-12 are most commonly used. Draft 7 has the best compatibility — recommend using it first. Most validation libraries support Draft 7.
Can Schemas and TypeScript Interfaces Be Converted?
Yes. Use typescript-json-schema to generate Schema from TS, or json-schema-to-typescript to generate TS interfaces from Schema. Tools automate this process.
Can JSON Schema Validate Nested Objects?
Yes. JSON Schema natively supports nested object definitions using recursive properties. The $ref keyword references defined sub-schemas to avoid duplication.
This article is brought to you by ToolVault. More developer tools at the homepage.
Related Tools
Related Articles
HTML Table to JSON: How to Preserve Rows, Columns and Structure
Converting an HTML table from a web page to JSON — how to keep headers, handle merged cells and nested structure? Step-by-step with our HTML table to JSON tool.
Excel to JSON: Dates Become Numbers / Chinese Garbled — Fix
When converting Excel to JSON, dates turn into numbers like 44927, Chinese is garbled, empty cells vanish? Explains Excel serial dates and encoding pitfalls, with our Excel to JSON tool.
The Complete Guide to Table Format Conversion: Excel, CSV, JSON, Markdown, and HTML
A full walkthrough of converting between Excel, CSV, JSON, Markdown, and HTML tables: format characteristics, conversion paths, hands-on workflows, and common pitfalls — 12 free online converters in one place.