📋JSON Schema Converter: Generate Validation Schemas Automatically
Convert JSON to JSON Schema with one click. Automatically detects types and formats, generates Draft 2020-12 or Draft 07 schemas, and documents your APIs professionally.
JSON Schema Converter: Generate Validation Schemas Automatically
API documentation and validation are essential, but creating JSON Schema manually is tedious and error-prone. Today we introduce our JSON Schema Converter - a tool that automatically generates JSON Schema from your JSON data.
What is JSON Schema?
JSON Schema is the de facto standard for describing and validating JSON structures. It's used in:
- OpenAPI/Swagger - REST API documentation
- API Gateway - Request/response validation
- Form Generation - Automatic UI generation
- Data Validation - Libraries like Ajv, JSON Schema Validator
- IDE Autocomplete - IntelliSense and code completion
Practical Example
Input JSON:
{
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"active": true
}
Generated JSON Schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer" },
"active": { "type": "boolean" }
},
"additionalProperties": false
}
Note how the converter:
- Detected all types correctly
- Identified the email and added
"format": "email" - Distinguished
integerfromnumber - Set
additionalProperties: falsefor better security
Key Features
Smart Auto-Detection
The converter analyzes your data and automatically detects:
Primitive Types
- string - Text
- number - Decimal numbers (3.14, 2.5)
- integer - Whole numbers (42, 100)
- boolean - true/false
- null - Null values
Complex Types
- object - Nested objects with properties
- array - Arrays with element type inference
Format Detection
When enabled, the converter automatically detects common formats:
| Format | Example | Use |
|---------|---------|-----|
| email | user@example.com | Email validation |
| uri | https://example.com | URL/URI |
| uuid | 550e8400-e29b-41d4-a716-446655440000 | Unique identifiers |
| date-time | 2025-11-17T15:30:00Z | ISO 8601 timestamp |
| date | 2025-11-17 | Date only |
| time | 15:30:00 | Time only |
| ipv4 | 192.168.1.1 | IPv4 address |
| ipv6 | 2001:0db8::1 | IPv6 address |
Example with format detection:
{
"user": {
"email": "admin@example.com",
"website": "https://example.com",
"id": "550e8400-e29b-41d4-a716-446655440000",
"created": "2025-11-17T15:30:00Z",
"ip": "192.168.1.1"
}
}
Generated Schema:
{
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"email": { "type": "string", "format": "email" },
"website": { "type": "string", "format": "uri" },
"id": { "type": "string", "format": "uuid" },
"created": { "type": "string", "format": "date-time" },
"ip": { "type": "string", "format": "ipv4" }
}
}
}
}
Configurable Options
Schema Title
Name your schema for better documentation:
{
"$schema": "...",
"title": "User Profile Schema",
"type": "object",
...
}
Make All Fields Required
Automatically make all fields required:
{
"type": "object",
"properties": { ... },
"required": ["name", "email", "age"]
}
null fields are excluded from the required list.
Schema Version
Choose between:
- Draft 2020-12 (Latest) - Full support for the latest features
- Draft 07 - Compatibility with older tools
Nested Objects Support
Complete handling of complex structures:
{
"user": {
"profile": {
"name": "John",
"contacts": {
"email": "john@example.com",
"phone": "+1234567890"
}
},
"permissions": ["read", "write"],
"metadata": {
"created": "2025-11-17T10:00:00Z",
"updated": "2025-11-17T15:30:00Z"
}
}
}
The converter correctly generates all nesting levels with their respective schemas.
Array Support
Automatic element type inference:
{
"tags": ["typescript", "react", "vite"],
"scores": [95, 87, 92],
"users": [
{ "name": "Alice", "age": 30 },
{ "name": "Bob", "age": 25 }
]
}
Generated Schema:
{
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": { "type": "string" }
},
"scores": {
"type": "array",
"items": { "type": "integer" }
},
"users": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
}
}
}
}
}
Real-World Use Cases
1. API Documentation with OpenAPI
Quickly generate schemas for your OpenAPI specifications:
openapi: 3.0.0
paths:
/users:
post:
requestBody:
content:
application/json:
schema:
# Paste the generated schema here
type: object
properties:
name:
type: string
email:
type: string
format: email
2. Validation with Ajv
Use the schema for runtime data validation:
import Ajv from 'ajv'
import addFormats from 'ajv-formats'
const ajv = new Ajv()
addFormats(ajv)
const schema = {
// Generated schema from the converter
}
const validate = ajv.compile(schema)
const data = { name: "John", email: "john@example.com" }
if (validate(data)) {
console.log('Valid data')
} else {
console.log('Errors:', validate.errors)
}
3. Form Generation
Libraries like react-jsonschema-form can automatically generate forms:
import Form from '@rjsf/core'
const schema = {
// Generated schema
}
function MyForm() {
return (
<Form
schema={schema}
onSubmit={({ formData }) => console.log(formData)}
/>
)
}
4. TypeScript Interface Generation
Use tools like json-schema-to-typescript to generate types:
npm install -g json-schema-to-typescript
# Generate TypeScript types from schema
json-schema-to-typescript schema.json > types.ts
Output:
export interface UserProfile {
name: string
email: string
age: number
active: boolean
}
5. Database Schema Design
Use JSON Schema as a base for defining database structures (MongoDB, PostgreSQL JSONB, etc.):
// MongoDB Schema Validation
db.createCollection("users", {
validator: {
$jsonSchema: {
// Schema generated by the converter
}
}
})
Recommended Workflow
1. Rapid Prototyping
Sample data → JSON Schema Converter → Base schema → Manual refinement
1. Create a representative example of your data 2. Generate the schema with the converter 3. Add additional constraints (min/max, pattern, enum, etc.)
2. API-First Development
Request/Response examples → Schema → OpenAPI Spec → Code Generation
1. Define request/response examples 2. Generate schemas for each 3. Integrate into OpenAPI specification 4. Generate client/server code
3. Documentation-Driven
JSON data → Schema → Auto-generated docs → Published API docs
Use tools like Redoc or Swagger UI to publish documentation generated from schemas.
Best Practices
1. Use Representative Data
Provide a complete example with all possible fields:
// Incomplete
{
"name": "John"
}
// Complete
{
"name": "John",
"email": "john@example.com",
"age": 30,
"active": true,
"roles": ["user", "admin"],
"metadata": {
"created": "2025-11-17T10:00:00Z"
}
}
2. Check Detected Formats
Always verify that detected formats are correct:
- A code might look like a UUID but not be one
- A string might accidentally match the email pattern
3. Add Constraints Manually
The generated schema is a starting point. Add:
minLength/maxLengthfor stringsminimum/maximumfor numberspatternfor regex validationenumfor predefined values
{
"type": "string",
"format": "email",
"minLength": 5,
"maxLength": 100,
"pattern": "^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$"
}
4. Version Your Schemas
Add versioning when you change schemas:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/user-profile/v2.json",
"title": "User Profile Schema",
"version": "2.0.0",
...
}
5. Use additionalProperties
The converter sets additionalProperties: false for security. Consider whether to:
- Keep it
falsefor strict validation - Set it to
truefor flexibility - Define a specific schema for additional properties
Integration with Popular Tools
VS Code JSON Schema Validation
Configure VS Code to validate JSON with your schema:
// settings.json
{
"json.schemas": [
{
"fileMatch": ["user-profile.json"],
"url": "./schemas/user-profile.schema.json"
}
]
}
Postman Schema Validation
Use the schema to validate API responses in Postman:
// Test script
pm.test("Response matches schema", function() {
const schema = {
// Generated schema
}
pm.response.to.have.jsonSchema(schema)
})
Jest Testing
Validate data in tests:
import Ajv from 'ajv'
const ajv = new Ajv()
const schema = { /* schema */ }
const validate = ajv.compile(schema)
test('API response is valid', async () => {
const response = await fetch('/api/users/1')
const data = await response.json()
expect(validate(data)).toBe(true)
})
Limitations and Considerations
1. Example-Based Inference
The generated schema is based on the example provided. If your JSON has:
{ "age": 30 }
The schema will be "type": "integer", but if age could be null in the future, you'll need to add manually:
{ "type": ["integer", "null"] }
2. Heterogeneous Arrays
If the array contains mixed types, the converter uses the first element:
{
"items": [1, "two", true] // Difficult to handle
}
Better to use homogeneous arrays:
{
"numbers": [1, 2, 3],
"strings": ["one", "two"]
}
3. Circular References
Structures with circular references are detected and marked:
{
"description": "Circular reference detected"
}
You'll need to handle them manually with $ref.
Upcoming Features
We're working on:
- AVRO Schema Support - JSON → AVRO conversion for Kafka/Confluent
- Schema Refinement UI - Visual editor to add constraints
- Batch Conversion - Convert multiple JSONs at once
- Schema Merging - Combine schemas from multiple examples
- TypeScript Generation - Generate types directly from schema
- Schema Library - Save and reuse common schemas
Privacy and Open Source
Like all our tools:
- 100% client-side - Your JSON data never leaves your browser
- Zero tracking - No analytics on processed data
- Open source - Public code on GitHub
- Offline-ready - Works without an internet connection
Try It Now
The JSON Schema Converter is available for free:
Useful Resources
- JSON Schema Specification
- Ajv JSON Schema Validator
- Understanding JSON Schema
- json-schema-to-typescript
Feedback
Have suggestions? Found a bug? Want a feature?
- admin@thejord.it
- GitHub Issues
- Contribute to the open source project!
---
Conclusion: Documenting and validating your APIs has never been easier. The JSON Schema Converter saves you hours of manual work by generating accurate, ready-to-use schemas. Try it today!