JSON Type Definition

Validate a JSON value against a JSON Type Definition schema (RFC 8927) — a small, portable, cross-implementation schema language. Unlike the framework's fluent b.safeSchema builder, a JTD schema is plain JSON you can share with any JTD implementation (and generate code from), which makes it the right choice for interop contracts.

validate(schema, instance) returns an array of errors, each a { instancePath, schemaPath } pair pointing at the offending value and the schema rule it broke (an empty array means valid). All eight schema forms are supported — empty, type, enum, elements, properties, values, discriminator, and ref (with definitions) — and a malformed schema is rejected at compile time rather than mis-validating.

b.jtd.validate(schema, instance) #

stable0.12.62soc2

Validate a JSON value against a JSON Type Definition schema (RFC 8927) and return the array of validation errors — each a { instancePath, schemaPath } pair of token arrays naming the offending value and the schema rule it broke. An empty array means the instance is valid. All eight schema forms are supported. The schema itself is checked for well-formedness first; a malformed schema throws jtd/bad-schema rather than silently mis-validating.

b.jtd.validate({ properties: { id: { type: "uint32" } } }, { id: -1 });
// -> [ { instancePath: ["id"], schemaPath: ["properties", "id", "type"] } ]

b.jtd.isValid(schema, instance) #

stable0.12.62

Convenience boolean form of validatetrue when the instance conforms to the JTD schema (no errors). Throws jtd/bad-schema on a malformed schema.

b.jtd.isValid({ type: "string" }, "hello");   // -> true

Last updated 2026-08-08T16:39:49.652Z by seeder.