JSON Tools

JSON Schema Validator: Validate JSON Data Against a Schema

Validate JSON data against a JSON Schema (draft-07) definition. Catch type errors, missing required fields, and constraint violations instantly.

Published January 15, 2025Updated June 1, 20256 min read

Try the free online tool

Runs entirely in your browser — no signup, no uploads.

Open Tool

Syntax validation confirms that a JSON document is well-formed. Schema validation goes much further: it checks that the data has the right structure, the right types, and the right constraints — that required fields are present, that strings match expected patterns, that numbers fall within valid ranges, and that objects contain only allowed properties.

JSON Schema is the standard way to describe the shape and rules of a JSON document. It is used to validate API request and response bodies, configuration files, database documents, and event payloads. A JSON Schema document is itself JSON, making it easy to version, share, and integrate into automated workflows.

This tool validates a JSON document against a JSON Schema (supporting draft-07, the most widely deployed version) and reports every validation error with the exact path, the violated keyword, and a human-readable message — so you know exactly what to fix.

What Is JSON Schema?

JSON Schema (jsonschema.org) is a vocabulary for annotating and validating JSON documents. A schema is itself a JSON document that describes the structure, types, and constraints that a valid JSON instance must satisfy. The schema specification has evolved through several drafts: draft-04, draft-06, draft-07, draft-2019-09, and draft-2020-12.

A JSON Schema can express: the type of a value (`string`, `number`, `integer`, `boolean`, `array`, `object`, `null`), required properties, property types and their own sub-schemas, minimum and maximum values for numbers, minimum and maximum lengths for strings, regex patterns for strings, minimum and maximum items for arrays, enum values, and composition rules using `allOf`, `anyOf`, `oneOf`, and `not`.

JSON Schema is used across the industry for API contract definition (OpenAPI 3.x uses JSON Schema for request/response bodies), configuration file validation (VS Code uses JSON Schema to provide IntelliSense for JSON config files), and data pipeline validation (ensuring data quality before processing).

  • `type` — restricts the value to one or more JSON types
  • `required` — lists property names that must be present in an object
  • `properties` — defines sub-schemas for specific object properties
  • `minimum` / `maximum` — numeric range constraints
  • `minLength` / `maxLength` — string length constraints
  • `pattern` — regex pattern that a string value must match
  • `enum` — restricts the value to a fixed set of allowed values
  • `allOf` / `anyOf` / `oneOf` — schema composition for complex validation rules

How to Use This Tool

Provide both the JSON data and the JSON Schema, and the tool reports every constraint violation with precise location and reason.

  1. 1

    Paste your JSON data

    Enter the JSON document you want to validate — an API response, a config file, a form submission — in the left panel.

  2. 2

    Paste your JSON Schema

    Enter the JSON Schema definition in the right panel. If you do not have a schema yet, use the tool to generate a basic schema from your sample data.

  3. 3

    Run validation

    Click Validate. The tool checks every constraint in the schema against every value in the data document.

  4. 4

    Review validation errors

    Each error shows the JSON path of the invalid value, the schema keyword that was violated, and a human-readable description of why the value is invalid.

  5. 5

    Fix and re-validate

    Correct the JSON data or adjust the schema constraints and re-validate until no errors remain.

Writing a JSON Schema: Quick Start

A minimal JSON Schema for a user object demonstrates the most important keywords. Understanding this example covers 80% of real-world schema writing.

The schema below requires an object with three fields: `id` (integer), `name` (string, 1-100 characters), and `email` (string matching an email pattern). Any additional properties are disallowed.

  1. 1

    Define the type

    Start with `{"type": "object"}` to require the value to be a JSON object. Use `"array"` for arrays, `"string"` for strings, and so on.

  2. 2

    Declare required fields

    Add `"required": ["id", "name", "email"]` to list the field names that must be present. Any object missing these fields will fail validation.

  3. 3

    Define property schemas

    Add a `"properties"` object where each key is a property name and each value is a sub-schema: `{"id": {"type": "integer"}, "name": {"type": "string", "minLength": 1}}`.

  4. 4

    Add constraints

    Refine each property with constraints: `"minimum"` and `"maximum"` for numbers, `"minLength"` and `"pattern"` for strings, `"minItems"` for arrays.

  5. 5

    Disallow extra properties

    Add `"additionalProperties": false` to reject any properties not listed in `"properties"`. This is useful for strict API contracts but too restrictive for extensible formats.

Common Use Cases

JSON Schema validation is a foundational practice for data quality, API reliability, and developer experience.

  • API request validation — validate incoming request bodies in your API gateway or middleware before they reach business logic, returning clear error messages to API consumers.
  • OpenAPI / Swagger integration — JSON Schema is the core of OpenAPI 3.x schema definitions; validate response bodies against your OpenAPI spec in integration tests.
  • Configuration file validation — VS Code and JetBrains IDEs use JSON Schema to provide autocomplete and inline validation for configuration files; publish your schema to SchemaStore.org.
  • Event-driven architecture — validate event payloads in Kafka, SNS, or EventBridge consumers to catch schema drift before it causes downstream processing failures.
  • Form validation — define validation rules in JSON Schema and use libraries like `ajv` to validate form data on both client and server with a single shared schema.

Tips and Best Practices

Writing effective JSON Schemas requires balancing strictness with flexibility. Over-constraining a schema makes it brittle; under-constraining it defeats the purpose.

  • Start permissive, tighten incrementally — begin with type constraints only, then add required fields and value constraints as your data model stabilizes.
  • Use `$ref` for reusable sub-schemas — define common shapes (pagination envelope, error response, address object) once in a `$defs` / `definitions` section and reference them with `$ref` to avoid duplication.
  • Test with both valid and invalid data — write test cases with data you expect to pass and data you expect to fail. A schema that only accepts the happy path is incomplete.
  • Be careful with `additionalProperties: false` — it makes your schema brittle to adding new fields. In many APIs, it is safer to validate only the fields you care about and ignore extras.
  • Use `ajv` in production — Ajv is the fastest and most compliant JavaScript JSON Schema validator. It compiles schemas to optimised validation functions and supports all modern drafts.

Frequently Asked Questions

What is the difference between JSON validation and JSON Schema validation?

JSON (syntax) validation checks that the text is well-formed JSON — correct brackets, quoted keys, no trailing commas. JSON Schema validation checks that the parsed data conforms to a defined structure and set of constraints. You need both: syntax validation first, then schema validation.

Which JSON Schema draft should I use?

Draft-07 is the most widely supported across libraries and tools and is a safe default. If your toolchain supports it, draft-2020-12 is the current standard with improved `unevaluatedProperties`, `prefixItems`, and dynamic references. Check the support matrix of your target library before using a newer draft.

How do I generate a JSON Schema from sample data?

Several tools can infer a draft schema from sample JSON: `genson` (Python), `quicktype.io` (online, also generates types), and many online JSON Schema generators. Treat the generated schema as a starting point — review and tighten constraints manually before using it in production.

How do I validate JSON Schema in Node.js?

Use Ajv: `npm install ajv`. Then: `const Ajv = require('ajv'); const ajv = new Ajv(); const validate = ajv.compile(schema); const valid = validate(data); if (!valid) console.log(validate.errors);`. Ajv is the de facto standard JavaScript JSON Schema validator and supports all major drafts.

Can JSON Schema validate nested objects and arrays?

Yes. The `properties` keyword defines sub-schemas for each property (which can themselves be object schemas with their own `properties`). The `items` keyword defines the schema for array elements, and `prefixItems` (draft-2020-12) or `items` with an array (draft-07) define per-position schemas for tuples.

How do I express OR logic in JSON Schema?

Use `anyOf` to require that data matches at least one of several schemas: `{"anyOf": [{"type": "string"}, {"type": "null"}]}` allows either a string or null. Use `oneOf` to require exactly one match. Use `allOf` to require all listed schemas to pass simultaneously.

How do I allow a property to be either a string or null?

In draft-07: `{"type": ["string", "null"]}` — the `type` keyword accepts an array of types. In draft-2020-12 you can also use `{"anyOf": [{"type": "string"}, {"type": "null"}]}`. The array syntax is more concise and widely supported.

Can I reference external schemas with `$ref`?

Yes. `$ref` can reference an external URL (`"$ref": "https://example.com/schemas/address.json"`) or a local path. For browser-based tools, external `$ref` resolution may be blocked by CORS. For production use, embed referenced schemas in the `$defs` section or bundle them with tools like `json-schema-bundler`.

json schemajsonjson schema validatordata validationapi validation

Ready to use this tool?

Free, instant, no account required. Runs entirely in your browser.

Open Tool

More JSON Tools Guides