Schema Validation

Validate your JSON with JSON Schema. Learn how to define, apply, and test schemas for robust, error-free data.

Why Use JSON Schema?

Basic Schema Structure

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1
    },
    "age": {
      "type": "integer",
      "minimum": 0
    }
  },
  "required": ["name", "age"]
}

Common Validation Keywords

Example: User Profile Schema

Let's look at a more complex example that validates a user profile:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["id", "username", "email"],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^usr_[a-zA-Z0-9]{8}$"
    },
    "username": {
      "type": "string",
      "minLength": 3,
      "maxLength": 30
    },
    "email": {
      "type": "string",
      "format": "email"
    }
  }
}

Validation Tools

Several tools can help you validate JSON against schemas:

Best Practices

Try It Yourself

Check out our example files: