xschema

Runtime Mode

Convert JSON Schema to validators at runtime (coming soon)

Runtime mode is coming soon. This section documents the planned API.

What is Runtime Mode?

Runtime mode allows you to convert JSON Schema to validators dynamically at runtime, rather than at build time.

// Planned API
import { convert } from "@xschemadev/runtime";

const jsonSchema = await fetch("/api/schema/user").then(r => r.json());
const UserSchema = convert(jsonSchema, { adapter: "zod" });

// Use like any other Zod schema
const result = UserSchema.safeParse(data);

When to Use Runtime Mode

Use CaseRecommended Mode
Schemas known at build timeFramework (build-time)
Dynamic schemas from APIRuntime
Schema registry integrationRuntime
Multi-tenant apps with custom schemasRuntime
Prototyping/REPL usageRuntime

Framework vs Runtime

AspectFramework (Build-time)Runtime
TypeScript typesFull inferenceGeneric types
Bundle sizeTree-shaken, minimalIncludes converter
PerformanceZero overheadConversion cost per schema
Schema discoveryConfig filesProgrammatic
Compliance testedYesYes

Planned API Preview

Basic Usage

import { convert } from "@xschemadev/runtime";
import type { z } from "zod";

// Convert a schema
const schema = convert<z.ZodType>(jsonSchema, { adapter: "zod" });

// Use the schema
const result = schema.safeParse(data);

With Caching

import { createRuntime } from "@xschemadev/runtime";

const runtime = createRuntime({
  adapter: "zod",
  cache: true, // Cache converted schemas
});

// Convert and cache
const UserSchema = runtime.convert(userJsonSchema);
const OrderSchema = runtime.convert(orderJsonSchema);

With Multiple Adapters

import { createRuntime } from "@xschemadev/runtime";

const zodRuntime = createRuntime({ adapter: "zod" });
const arktypeRuntime = createRuntime({ adapter: "arktype" });

// Same schema, different validators
const zodSchema = zodRuntime.convert(jsonSchema);
const arktypeSchema = arktypeRuntime.convert(jsonSchema);

Planned Features

  • All adapters supported: Zod, ArkType, Effect, Valibot
  • Same compliance: Runtime uses the same conversion logic as build-time
  • Caching: Optional caching of converted schemas
  • Streaming: Convert schemas as they're received
  • Bundle options: Bring your own adapter or use bundled

Current Status

Runtime mode is in development. For now, use Framework mode which generates validators at build time.

On this page