Last updated
Example: Nested Object Schema
// Input JSON:
{
"user": {
"id": 1,
"name": "Alice",
"address": {
"street": "123 Main St",
"city": "New York",
"zip": "10001",
"country": "US"
}
}
}
// Generated Schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" },
"zip": { "type": "string", "pattern": "^\\d{5}$" },
"country": { "type": "string", "minLength": 2, "maxLength": 2 }
},
"required": ["street", "city", "zip", "country"]
}
},
"required": ["id", "name", "address"]
}
},
"required": ["user"]
}
Example: Array of Objects Schema
// Input JSON:
[
{ "id": 1, "name": "Widget A", "price": 9.99, "inStock": true },
{ "id": 2, "name": "Widget B", "price": 14.99, "inStock": false },
{ "id": 3, "name": "Widget C", "price": 4.99, "inStock": true }
]
// Generated Schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"price": { "type": "number", "minimum": 0 },
"inStock": { "type": "boolean" }
},
"required": ["id", "name", "price", "inStock"]
}
}
Example: Schema with Enum Detection
// Input JSON (multiple samples analyzed):
[
{ "status": "pending", "priority": "low" },
{ "status": "active", "priority": "medium" },
{ "status": "completed", "priority": "high" },
{ "status": "cancelled", "priority": "low" }
]
// Generated Schema (enum values inferred):
{
"type": "array",
"items": {
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": ["pending", "active", "completed", "cancelled"]
},
"priority": {
"type": "string",
"enum": ["low", "medium", "high"]
}
},
"required": ["status", "priority"]
}
}
Example: OpenAPI Schema Component
// Input JSON (API response):
{
"id": 1,
"username": "alice",
"email": "alice@example.com",
"createdAt": "2024-01-15T14:30:00Z",
"updatedAt": "2024-03-10T09:15:00Z"
}
// Generated Schema (OpenAPI 3.0 compatible):
{
"User": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "Unique identifier"
},
"username": {
"type": "string",
"description": "User's login name"
},
"email": {
"type": "string",
"format": "email",
"description": "User's email address"
},
"createdAt": {
"type": "string",
"format": "date-time",
"description": "Account creation timestamp"
},
"updatedAt": {
"type": "string",
"format": "date-time",
"description": "Last update timestamp"
}
},
"required": ["id", "username", "email"]
}
}
Example: Schema with $defs (Reusable Types)
// Input JSON:
{
"order": {
"id": "ORD-001",
"customer": { "id": 1, "name": "Alice", "email": "alice@example.com" },
"items": [
{ "product": { "id": 10, "name": "Widget", "price": 9.99 }, "qty": 2 }
],
"shippingAddress": { "city": "New York", "zip": "10001" }
}
}
// Generated Schema (with reusable $defs):
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$defs": {
"Customer": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"email": { "type": "string", "format": "email" }
},
"required": ["id", "name", "email"]
},
"Product": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"price": { "type": "number", "minimum": 0 }
},
"required": ["id", "name", "price"]
}
},
"type": "object",
"properties": {
"order": {
"type": "object",
"properties": {
"id": { "type": "string" },
"customer": { "$ref": "#/$defs/Customer" },
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"product": { "$ref": "#/$defs/Product" },
"qty": { "type": "integer", "minimum": 1 }
}
}
}
}
}
}
}
Generated TypeScript Interface
// From the same User JSON, generate TypeScript:
interface User {
id: number;
username: string;
email: string;
createdAt: string; // ISO 8601 date-time
updatedAt?: string; // optional
}
Paste your sample JSON to generate a JSON Schema automatically. Refine the generated schema by adding descriptions, constraints, and enum values to make it a complete API contract.
Example: Simple Object Schema
// Input JSON:
{
"id": 42,
"name": "Alice Smith",
"email": "alice@example.com",
"age": 30,
"active": true,
"score": 98.5,
"notes": null
}
// Generated JSON Schema (Draft 7):
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer", "minimum": 0 },
"active": { "type": "boolean" },
"score": { "type": "number" },
"notes": { "type": ["string", "null"] }
},
"required": ["id", "name", "email", "age", "active"]
}