JSON Schema Validator: Validate a Document Against a Schema

What a JSON Schema validator checks, what it leaves unchanged, where copied JSON and Unicode text cause problems, and when a validator is the right tool.

A JSON Schema validator takes two inputs, a JSON document (the instance) and a JSON Schema, and reports whether the document meets the rules in the schema. This review covers what that check does and does not do, how it differs from formatting and from text transformations, and what to watch for when JSON is copied, shared or pasted into a checker. No specific tool was tested for this article, so it describes documented behavior of the JSON Schema specification and general parsing principles, not the features of any product.

Is a schema validator the right tool for your task?

A schema validator suits you if you need to confirm that a document has the expected structure: required fields are present, values have the right types, numbers fall within ranges, strings match patterns and unexpected properties are rejected. Its main benefit is that it turns an informal agreement about data shape into a repeatable, checkable rule. That makes it useful for API payloads, configuration files and data exchanged between teams.

The main tradeoff is that the result is only as good as the schema and depends on the specification version the validator supports. A permissive schema passes nearly anything. A schema written for one draft can behave differently in a validator that assumes another. Validation also confirms structure, not truth: a correctly typed but wrong value still passes.

A schema validator is unnecessary in some cases. If you only need to know whether text is syntactically valid JSON, a plain JSON parser or syntax checker is enough. If you want readable indentation, use a formatter. If the data is sensitive and you cannot confirm how a web-based checker handles input, a local library or command-line validator is the safer choice.

What validation actually changes

Validation is a read-only check. It parses the document and the schema, evaluates the schema keywords against the parsed data, and produces a pass/fail result, usually with a list of errors. The stored characters of your document are not rewritten. Here it differs from the transformations often grouped with it under "text tools".

  • Syntax checking: confirms the text parses as JSON. It knows nothing about required fields or types.
  • Schema validation: confirms the parsed data meets the rules in a schema. It does not modify the data.
  • Formatting (pretty-printing or minifying): rewrites the whitespace between tokens. The data stays the same, but the stored characters change. Some tools may also reorder keys or re-serialize numbers, so the output text may not match the original byte for byte.
  • Reversal, mirroring and decorative fonts: these change characters or their visual presentation. Applied to JSON, they almost always produce text that no longer parses. They have no role in schema validation.

The words "reverse" and "mirror" can be ambiguous in this context. Neither describes a validation operation. If a tool offers to "mirror" a schema or document, check its documentation to see whether it means copying, converting between formats or something else. Do not assume it is a validator feature.

A worked example

The schema below requires an object with a positive integer id and a non-empty name. It allows an optional array of string tags and rejects any other properties.

{
  "type": "object",
  "properties": {
    "id": { "type": "integer", "minimum": 1 },
    "name": { "type": "string", "minLength": 1 },
    "tags": { "type": "array", "items": { "type": "string" } }
  },
  "required": ["id", "name"],
  "additionalProperties": false
}

This document is syntactically valid JSON, but it fails the schema:

{
  "id": "42",
  "tags": ["a", 3],
  "nickname": "x"
}

Applying the schema rules gives four failures. Validators locate errors with a path into the document, commonly written as a JSON Pointer. The exact message wording varies between implementations.

Location | Rule | Reason
/id | type: integer | The value is the string "42", not a number
(root) | required | The property "name" is missing
/tags/1 | items: type string | The value 3 is a number
/nickname | additionalProperties: false | The property is not declared in properties

Some validators stop at the first error and others report all of them. If you are fixing a document in one pass, check which behavior a tool uses.

Specification versions matter

JSON Schema has several published drafts, including draft-04, draft-06, draft-07, 2019-09 and 2020-12. A schema declares the draft it was written for with the $schema keyword. Some keywords changed meaning or were added between drafts. For example, how array item rules are expressed changed in 2020-12. In 2019-09 and 2020-12, the format keyword is treated as an annotation by default rather than an enforced check, unless the validator is configured to assert it. A checker that does not state which drafts it supports leaves you unable to judge whether a pass is meaningful. Treat that as a gap to resolve before relying on it.

Will your JSON survive copying and sharing?

Most practical validation failures that are not schema errors come from text changing on its way into the checker. These problems arise from how text is copied and handled. They are not specific to any one tool.

  • Typographic quotes: word processors, chat apps and some note tools may replace straight double quotes with curly ones. JSON requires the straight quotation mark, so the document will no longer parse.
  • Invisible characters: non-breaking spaces, zero-width characters and a leading byte order mark can be introduced during copy and paste. Some parsers reject them, and inside strings they silently change the value.
  • Lookalike characters: decorative "font" generators substitute visually similar Unicode characters. A key that looks like "name" but uses substituted letters is a different key, so required or properties checks will fail in ways that are hard to see.
  • Large numbers: parsers that store numbers as double-precision floating point, which is common in JavaScript, can lose precision on very large integers. A browser-based checker may therefore validate a slightly different value than the one you pasted.
  • Duplicate keys: the JSON standard says object names should be unique but does not define what happens when they repeat. Parsers differ, often keeping the last value, so a validator may never see one of the duplicates.

Unicode also affects string-length rules. The JSON Schema specification defines minLength and maxLength in terms of characters. Implementations do not all count the same way: some count code points and some count UTF-16 code units. Neither approach matches what a reader perceives as one character when combining marks or multi-code-point emoji are involved. An accented letter built from a base letter plus a combining mark, or an emoji sequence joined with zero-width joiners, can count as two or more. If your schema enforces lengths on user-facing text, test it with such characters in the validator you actually use instead of assuming a result.

To share a document or an error report, use plain text in a code block or an attached file. Do not use rich text or screenshots. Plain text keeps the characters intact for the next person's parser. A screenshot cannot be validated, copied reliably or read as text by assistive technology.

Accessibility and readability of results

How readable validation output is depends on the tool, and no tool-specific evidence was available for this review. Some general points still apply. Error lists that give a path and a plain-language reason in text can be read by screen readers and copied into tickets. Errors shown only through color highlighting or inline markers in an editor may not be. Before adopting a checker, confirm with your own assistive technology that errors are announced as text. One successful rendering in one browser does not establish that it works elsewhere.

Privacy and handling of pasted data

A tool's appearance or marketing language says nothing reliable about whether pasted documents are sent to a server, logged or retained. Look for that information in the tool's documentation or privacy terms. If it is absent, assume you do not know. For documents containing credentials, personal data or proprietary configuration, a validator library run locally or in your own build pipeline avoids the question entirely.

Summary and open gaps

A JSON Schema validator is the right choice when you need a repeatable check of a document's structure and types, and it leaves your data unchanged. Its usefulness depends on a well-written schema, a clearly stated specification draft and clean plain-text input. For syntax-only checks, a parser is enough. For sensitive data, a local validator is preferable.

This review could not verify several things because no evidence about specific tools was supplied: which drafts a given checker supports, whether it reports all errors or only the first, how it counts string length, whether it asserts format, how it behaves with assistive technology, and how it handles submitted data. Each of these should be confirmed in a tool's documentation or by a small scoped test before you rely on its results.