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.
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.
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.
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.
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.
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.
JSON Schema Keywords Reference
The most important JSON Schema keywords you will use when defining API data types.
| Keyword | Description |
|---|---|
type | The data type: string, number, integer, boolean, array, object, null |
properties | Define the properties of an object type |
required | Array of property names that must be present |
items | Schema for array elements |
enum | Restrict values to a fixed set |
format | Semantic validation: email, uri, date-time, uuid, ipv4 |
minimum / maximum | Numeric range constraints |
minLength / maxLength | String length constraints |
pattern | Regex pattern for string validation |
default | Default value if not provided |
$ref | Reference another schema definition (for reuse) |
description | Human-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.