Define the structure and validation rules for your API responses
A schema (or data contract) is a blueprint that defines the structure, data types, and validation rules for your API responses. It ensures consistency and predictability in your mock data.
Mock API Builder supports various field types for realistic data:
Text data of any length
"name": "John Doe"Use for: names, descriptions, addresses
Integer or decimal values
"price": 29.99Use for: prices, quantities, IDs
True/false values
"isActive": trueUse for: flags, toggles, status
Email address format
"email": "user@example.com"Auto-validates email format
ISO 8601 date strings
"createdAt": "2025-01-15T10:30:00Z"Use for: timestamps, birthdays
Unique identifier
"id": "550e8400-e29b-41d4-a716-..."Use for: unique IDs
Web address format
"website": "https://example.com"Use for: links, avatar URLs
List of items
"tags": ["javascript", "react"]Use for: lists, collections
Nested data structure
"address": { "city": "NYC" }Use for: nested data
Limited set of values
"status": "active" | "pending"Use for: status, role, category
You have three ways to define your data schema:
Build your schema field-by-field using the visual interface:
Example: User Schema
Best for:
Write your schema directly in JSON format:
Best for:
• Complex nested structures
• Copy/paste from existing APIs
• Developers comfortable with JSON
Import complete schemas from OpenAPI/Swagger specifications:
Best for:
• Existing API specs
• Team standardization
• Large-scale projects
Create complex data structures with nested properties:
Define arrays containing complex objects:
Mark fields that must always have a value
required: ["id", "name", "email"]Set minimum and maximum character limits
minLength: 3, maxLength: 50Define acceptable numeric ranges
minimum: 0, maximum: 100Use regex for custom validation
pattern: "^[A-Z]{2}-[0-9]{4}$"Begin with basic fields, then add complexity as needed. Don't over-engineer from the start.
firstName,emailAddress
fn,em
Choose a convention and stick to it:
firstNamefirst_nameFirstNameAlways include: id,createdAt,updatedAt for better tracking
Keep your mock schema identical to your real API to avoid integration issues later.