Navigation

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

  1. Open the Schema Generator.
  2. Paste your sample JSON in the left editor.
  3. 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"]
}
  1. Copy the schema for use in your application.

โœจ Smart Detection

The Schema Generator automatically identifies:

PatternDetected 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 required by 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 null values as type unions.

๐Ÿ’ก Workflow Tips

  1. Generate โ†’ Validate: Create a schema from a "golden" sample, then use the Validator to check all future payloads against it.
  2. Generate โ†’ Document: Copy the schema into your OpenAPI/Swagger spec for instant API documentation.
  3. 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.