Developer Tool

JSON to JSON Schema Converter

Generate JSON Schema from your JSON examples. Use JSON Schema to validate API requests, generate forms, enforce data contracts, and create self-documenting APIs with Specway.

JSON to JSON Schema: Before & After

Here is a typical JSON response and the JSON Schema that validates it. The schema adds type annotations, required fields, format constraints, and descriptions.

Input: JSON Example

{
  "id": 123,
  "name": "Jane Smith",
  "email": "jane@example.com",
  "age": 28,
  "is_active": true,
  "roles": ["admin", "editor"],
  "address": {
    "street": "123 Main St",
    "city": "San Francisco",
    "state": "CA",
    "zip": "94102"
  },
  "created_at": "2025-01-15T10:30:00Z"
}

Output: JSON Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer",
      "description": "Unique identifier"
    },
    "name": {
      "type": "string",
      "description": "Full name of the user"
    },
    "email": {
      "type": "string",
      "format": "email",
      "description": "Email address"
    },
    "age": {
      "type": "integer",
      "minimum": 0,
      "description": "Age in years"
    },
    "is_active": {
      "type": "boolean",
      "description": "Whether the account is active"
    },
    "roles": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "User roles"
    },
    "address": {
      "type": "object",
      "properties": {
        "street": { "type": "string" },
        "city": { "type": "string" },
        "state": { "type": "string" },
        "zip": { "type": "string", "pattern": "^[0-9]{5}$" }
      },
      "required": ["street", "city", "state", "zip"]
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "description": "Account creation timestamp"
    }
  },
  "required": ["id", "name", "email"]
}

Why Use JSON Schema?

JSON Schema is the foundation of modern API development. Here are the most common use cases.

API Request/Response Validation

Validate incoming API requests against a schema before processing. Reject malformed data at the edge and return clear error messages. JSON Schema is the foundation of OpenAPI specification data types.

Example: Ensure POST /users requests include required fields like name and email, and that age is a positive integer.

Form Generation

Auto-generate user-friendly forms from JSON Schema. Libraries like react-jsonschema-form and ajv render forms with proper input types, validation, and error messages based on your schema definition.

Example: A schema with type: "string", format: "email" renders as an email input with built-in validation.

Data Contracts Between Services

Define shared data contracts between microservices. When producer and consumer agree on a schema, changes are detected early and backwards compatibility is enforced. This is the foundation of contract testing.

Example: The User Service and Order Service share a User schema. Breaking changes trigger CI failures.

Configuration Validation

Validate YAML/JSON configuration files against a schema. Catch typos, missing fields, and invalid values before deployment. VS Code and other editors use JSON Schema to provide autocomplete for config files.

Example: Validate docker-compose.yml, package.json, or tsconfig.json against their official JSON schemas.

Documentation Generation

Generate API documentation from JSON Schema definitions embedded in your OpenAPI spec. Tools like Specway render schema definitions as interactive documentation with expandable objects and type annotations.

Example: Import an OpenAPI spec with JSON Schema definitions and get beautiful, interactive type documentation.

Code Generation

Generate TypeScript interfaces, Go structs, Python dataclasses, and more from JSON Schema definitions. Keep your types in sync across languages and eliminate manual type maintenance.

Example: A JSON Schema User definition generates TypeScript `interface User`, Go `type User struct`, and Python `@dataclass User`.

JSON Schema Keywords Reference

The most important JSON Schema keywords you will use when defining API data types.

KeywordDescription
typeThe data type: string, number, integer, boolean, array, object, null
propertiesDefine the properties of an object type
requiredArray of property names that must be present
itemsSchema for array elements
enumRestrict values to a fixed set
formatSemantic validation: email, uri, date-time, uuid, ipv4
minimum / maximumNumeric range constraints
minLength / maxLengthString length constraints
patternRegex pattern for string validation
defaultDefault value if not provided
$refReference another schema definition (for reuse)
descriptionHuman-readable description (shows in docs)

JSON Schema in OpenAPI Specifications

JSON Schema is used throughout OpenAPI specs to define request bodies, response bodies, parameters, and headers.

# OpenAPI 3.1 uses JSON Schema natively
openapi: 3.1.0
paths:
  /users:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                email:
                  type: string
                  format: email
                age:
                  type: integer
                  minimum: 0
                  maximum: 150
              required:
                - name
                - email
      responses:
        '201':
          description: User created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'

See Your Schemas Come to Life

Import your OpenAPI spec into Specway and see JSON Schema definitions rendered as interactive, expandable type documentation. Developers can explore nested objects, see constraints, and test requests against your schemas in the built-in playground.

Frequently Asked Questions

Common questions about JSON Schema.

Beautiful Schema Documentation

Import your OpenAPI spec with JSON Schema definitions and publish interactive API documentation in minutes.