Practical Examples

This section provides complete, real-world examples of JSON schemas for common use cases. Each example includes best practices and implementation notes.

Content Generation

Blog Post

Generate structured blog posts:

{
  "type": "object",
  "properties": {
    "title": { 
      "type": "string",
      "minLength": 10,
      "maxLength": 100
    },
    "author": { "type": "string" },
    "tags": {
      "type": "array",
      "items": { "type": "string" },
      "maxItems": 5
    },
    "content": {
      "type": "object",
      "properties": {
        "introduction": { "type": "string" },
        "body": { "type": "string" },
        "conclusion": { "type": "string" }
      },
      "required": ["introduction", "body", "conclusion"]
    }
  },
  "required": ["title", "author", "content"]
}
{
  "title": "Getting Started with JSON Schema",
  "author": "Jane Developer",
  "tags": ["json", "validation", "api"],
  "content": {
    "introduction": "JSON Schema provides a powerful way to validate JSON data.",
    "body": "With JSON Schema, you can define the structure, types, and constraints of your JSON documents. This ensures data consistency and helps catch errors early.",
    "conclusion": "Start using JSON Schema today to improve your API reliability."
  }
}

Data Classification

Sentiment Analysis

Analyze text sentiment:

{
  "type": "object",
  "properties": {
    "sentiment": {
      "type": "string",
      "enum": ["positive", "neutral", "negative"]
    },
    "confidence": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "keywords": {
      "type": "array",
      "items": { "type": "string" },
      "maxItems": 5
    }
  },
  "required": ["sentiment", "confidence"]
}
{
  "sentiment": "positive",
  "confidence": 0.92,
  "keywords": ["excellent", "amazing", "love", "perfect", "recommend"]
}

Data Extraction

Invoice Parser

Extract key invoice information:

{
  "type": "object",
  "properties": {
    "invoiceNumber": { "type": "string" },
    "date": { "type": "string", "format": "date" },
    "vendor": { "type": "string" },
    "customer": { "type": "string" },
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "description": { "type": "string" },
          "quantity": { "type": "number" },
          "price": { "type": "number" }
        },
        "required": ["description", "quantity", "price"]
      }
    },
    "total": { "type": "number" }
  },
  "required": ["invoiceNumber", "date", "vendor", "customer", "items", "total"]
}
{
  "invoiceNumber": "INV-2024-001",
  "date": "2024-03-15",
  "vendor": "Tech Solutions Inc.",
  "customer": "Acme Corporation",
  "items": [
    {
      "description": "Software License",
      "quantity": 10,
      "price": 299.99
    },
    {
      "description": "Support Package",
      "quantity": 1,
      "price": 1000.00
    }
  ],
  "total": 3999.90
}

API Response Modeling

Error Response

Standardized API error format:

{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": { "type": "string" },
        "message": { "type": "string" },
        "details": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "field": { "type": "string" },
              "issue": { "type": "string" }
            }
          }
        }
      },
      "required": ["code", "message"]
    },
    "status": { "type": "integer" }
  },
  "required": ["error", "status"]
}
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid request data",
    "details": [
      {
        "field": "email",
        "issue": "Invalid format"
      },
      {
        "field": "age",
        "issue": "Must be 18+"
      }
    ]
  },
  "status": 400
}

Form Processing

User Registration

Capture user registration data:

{
  "type": "object",
  "properties": {
    "username": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9_]{3,20}$"
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "password": {
      "type": "string",
      "minLength": 8
    },
    "profile": {
      "type": "object",
      "properties": {
        "firstName": { "type": "string" },
        "lastName": { "type": "string" },
        "bio": { 
          "type": "string",
          "maxLength": 200
        }
      },
      "required": ["firstName", "lastName"]
    },
    "acceptTerms": {
      "type": "boolean",
      "const": true
    }
  },
  "required": ["username", "email", "password", "acceptTerms"]
}
{
  "username": "johndoe2024",
  "email": "[email protected]",
  "password": "SecurePass123!",
  "profile": {
    "firstName": "John",
    "lastName": "Doe",
    "bio": "Software developer passionate about AI and open source"
  },
  "acceptTerms": true
}

Next Steps