Tutorial · 6 min read

How to Validate JSON Against a Schema Online (Generate & Validate)

JSON Schema is the contract that defines what valid JSON looks like for your application. But writing schemas from scratch is tedious, and manual validation is error-prone. This guide covers both sides — auto-generating a JSON Schema from sample data, and validating any JSON against it in real time — using the JSON Schema Validator.

Why JSON Schema Matters

Without a schema, a JSON API might return a string where you expected a number. A config file might be missing a required field. A database import might have unexpected fields that break your pipeline. JSON Schema solves this by defining rules for your data:

The challenge is that schemas are verbose to write. That's why the tool includes a Generate Schema feature that creates a draft schema from your JSON automatically.

1. Auto-Generate a JSON Schema from Sample Data

Start with sample JSON data and let the tool infer the schema:

[
  {
    "id": 1,
    "name": "Alice",
    "email": "alice@example.com",
    "role": "admin",
    "active": true,
    "profile": {
      "age": 32,
      "city": "Beijing"
    }
  }
]

Click Generate Schema in the toolbar. The tool produces a Draft 07 schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": { "type": "integer" },
      "name": { "type": "string" },
      "email": { "type": "string" },
      "role": { "type": "string" },
      "active": { "type": "boolean" },
      "profile": {
        "type": "object",
        "properties": {
          "age": { "type": "integer" },
          "city": { "type": "string" }
        },
        "required": ["age", "city"]
      }
    },
    "required": ["id", "name", "email", "role", "active", "profile"]
  }
}

The generated schema is a starting point — not perfect, but close. You can edit it to add constraints like minimum, pattern, enum, or remove optional fields from required.

2. Writing or Editing a Schema Manually

Once the schema is generated, you can refine it with additional constraints:

"role": {
  "type": "string",
  "enum": ["admin", "user", "editor", "viewer"]
},
"email": {
  "type": "string",
  "pattern": "^[\\w.-]+@[\\w.-]+\\.\\w+$"
},
"id": {
  "type": "integer",
  "minimum": 1
}

The schema editor provides syntax highlighting and real-time validation. As you type, any schema errors (like missing commas or invalid JSON) are highlighted. The schema and the JSON data validate simultaneously, so you can iterate quickly.

3. Validating JSON Against the Schema

With the schema in place, paste any JSON into the left panel to validate it instantly. The validator checks every field against the schema rules and reports:

Each error includes the exact JSON path, making it easy to locate and fix the problem. The error count badge shows how many issues exist at a glance.

4. Complete Validation Workflow

Here's the recommended workflow for schema validation:

  1. Start with sample data. Paste a representative JSON sample into the validator.
  2. Generate the schema. Click Generate Schema to create a Draft 07 schema.
  3. Add constraints. Add enum, pattern, minimum/maximum, and format to tighten validation.
  4. Test with variants. Paste different JSON inputs — valid and invalid — to verify the schema catches edge cases.
  5. Iterate. Adjust the schema based on validation results until it covers all allowed structures.

This workflow ensures your schema is both correct and complete before deployment.

Try the Free JSON Schema Validator

Generate schemas from sample JSON, validate in real time, fix errors instantly. No server uploads, no tracking.

Validate JSON Now →

Best Practices for JSON Schema Validation

Frequently Asked Questions

How do I validate JSON against a schema online?

Paste your JSON into the left panel and your JSON Schema into the right panel of the JSON Schema Validator. The tool validates in real time, showing errors with the exact JSON path, a human-readable description, and the schema rule that was violated.

Can the tool generate a JSON Schema automatically?

Yes. Click the Generate Schema button. The tool analyzes your JSON structure and creates a draft JSON Schema based on the detected data types. It sets the correct type for each field and marks all detected fields as required. Then you can edit the generated schema to add constraints or remove optional fields.

What JSON Schema draft version does the validator support?

The validator supports JSON Schema Draft 07, the most widely adopted version. It covers all standard keywords including type, properties, required, additionalProperties, enum, pattern, minimum, maximum, and format.

How are validation errors displayed?

Errors appear below the JSON input panel. Each error includes the exact path in the JSON that failed, a human-readable description, and the schema rule that was violated. A badge shows the total error count. Fix the issues and the errors clear instantly.

Is my JSON data safe with this validator?

100% safe. All validation happens in your browser. Your JSON data and schema never leave your computer. No server uploads, no storage, no tracking. The tool works offline once the page is loaded.