Generate a JSON Schema
Automatically infer a JSON Schema from sample data to validate payloads, generate documentation, and enforce data contracts.
Last updated:
JSON Schema describes the structure of JSON data. DataLensia can infer a starting schema from a sample payload; review it against your application rules before use.
๐ฉ The Scenario
You're building a REST API and need to document and validate the expected request body:
{
"id": "usr_abc123",
"email": "alice@example.com",
"age": 28,
"isPremium": true,
"tags": ["developer", "early-adopter"],
"address": {
"street": "123 Main St",
"city": "Barcelona",
"zip": "08001"
}
}
You need a JSON Schema that describes this structure for API documentation and request validation.
๐ ๏ธ Step-by-Step
- Open the Schema Generator.
- Paste your sample JSON in the left editor.
- Turn off Add Examples to reproduce the output below. The schema is generated in the right panel:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": { "type": "string" },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer" },
"isPremium": { "type": "boolean" },
"tags": {
"type": "array",
"items": { "type": "string" }
},
"address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" },
"zip": { "type": "string" }
},
"required": ["street", "city", "zip"]
}
},
"required": ["id", "email", "age", "isPremium", "tags", "address"]
}
- Copy the schema for use in your application.
โจ Smart Detection
The Schema Generator automatically identifies:
| Pattern | Detected Format |
|---|---|
alice@example.com | "format": "email" |
2025-01-15 | "format": "date" |
2025-01-15T10:30:00Z | "format": "date-time" |
550e8400-e29b-41d4-a716-446655440000 | "format": "uuid" |
https://example.com | "format": "uri" |
๐ Configuration Options
- Required fields detection: Non-null fields in a sample object are marked
requiredby default. For arrays of objects, a field must appear in every sampled item. - Description generation: Auto-generates human-readable descriptions for each field.
- Nullable support: Properly handles
nullvalues as type unions.
๐ก Workflow Tips
- Generate โ Validate: Create a schema from a "golden" sample, then use the Validator to check all future payloads against it.
- Generate โ Document: Copy the schema into your OpenAPI/Swagger spec for instant API documentation.
- Generate โ TypeScript: Use the Convert Tool to generate TypeScript types from the same data.
๐๏ธ Workspace Integration
When used inside a workspace (via the Tools panel), the Schema Generator auto-loads your current workspace data as input, so the schema is generated from your actual dataset.
๐ Try it now
Open the Schema Generator and paste a JSON object to generate a sample-derived schema.