Skip to content
yutils
Example

Input (schema + data)

Schema:
{ "type": "object", "required": ["name", "age"], "properties": { "name": { "type": "string" }, "age": { "type": "integer", "minimum": 0 } } }

Data:
{ "name": "Ada", "age": -3 }

Validation result

❌ 1 validation error
- /age: must be >= 0 (got -3)

Note

Draft 2020-12 with format support (email, uri, date, ...). Error paths use JSON Pointer (`/a/b`).

Usage / FAQ

When to use

  • Validate that an API response payload matches the defined schema
  • Pre-check form input data against the backend schema
  • Test a schema component from an OpenAPI / AsyncAPI definition in isolation
  • Compare behavior across drafts 4 / 6 / 7 / 2019-09 / 2020-12
  • Mirror ajv's validation results before shipping the schema

FAQ

Q.Which JSON Schema draft is used?
A.Draft 2020-12 by default. If the schema declares a `$schema`, that draft is honored (powered by ajv).
Q.Are format checks (email, uri, date) enabled?
A.Yes — ajv-formats provides the standard ones. The spec treats `format` as SHOULD-check; if you need strict validation, add explicit constraints.
Q.What is `/a/b` in the error path?
A.A JSON Pointer. `/a/b` points to `data.a.b`. Arrays use index segments: `/0`, `/1`, …
Fun facts
  • JSON Schema was first proposed in 2009 by Kris Zyp as an IETF Draft — a meta-schema for describing JSON data's structure, types, and constraints in JSON itself. As of 2024 it's still an IETF Internet Draft (the RFC process is in progress) — a 15-year 'draft' that's a fully living standard.

    JSON Schema — Official
  • The naming changed midway — Draft 1 through 7 (numbers), then Draft 2019-09 and Draft 2020-12 (year-month). The renames signal intentional compatibility breaks. Draft 2020-12 is the current de facto standard for modern API tooling (OpenAPI 3.1 also uses it).

    JSON Schema — Specification
  • In the Node.js ecosystem, ajv is famous as the fastest JSON Schema implementation — it pre-compiles a schema into a JavaScript function (`compile()` once, `validate()` forever), processing validations in tens of microseconds per call. It's the default dependency for Fastify and most OpenAPI tooling.

    Ajv — JSON Validator