Convert JSON Schema to Zod, Effect Schema, or plain TypeScript. One parser
resolves local, external and cyclic $ref links into standalone schemas and
types for every dialect from draft-04 to 2020-12.
Table of contents
- Three targets, one pipeline.
@utilize/zod,@utilize/effectand@utilize/typescriptshare the same parser, linker and naming rules, so they agree on what a schema means. $reflinks resolve. Local, external and cyclic, including$idand$anchor. External documents come from disk, HTTP, or memory withexternalSchemas.- Every definition is standalone.
$defsanddefinitionseach get their own schema or type. Zod also orders them by dependency. - Dialect-aware. Draft-04/06/07 are read natively, 2019-09 and 2020-12 are
normalized.
$schemais resolved per schema resource and$refsiblings are applied only where the dialect defines them. The per-dialect rules are in docs/dialects.md. - Proven on the official suite. Draft-07 scores 304/304 cases for Zod, 304/304 for Effect Schema and 192/285 for TypeScript; five dialects are measured. See supported features.
- Types without runtime.
@utilize/typescriptemits interfaces and aliases only; the output imports nothing.
pnpm add zod @utilize/json-schema
pnpm add -D @utilize/zod
utilize-zod user.json user.zod.tsGenerated schemas import structural format validators from
@utilize/json-schema/formats, so @utilize/json-schema is a runtime
dependency of the app, not only a generator dependency.
user.json:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "date"
}
},
"required": ["id"],
"additionalProperties": false
}user.zod.ts (banner omitted):
import { z } from 'zod';
export const User = z.strictObject({
id: z.iso.date().meta({ format: 'date' }),
});
export type User = z.infer<typeof User>;The date format keeps this example short. Formats that need structural
validation, such as email, hostname and uri, are imported from
@utilize/json-schema/formats as one validator per format, shared by every
schema that uses it.
The same three steps work for the other targets: @utilize/effect with
utilize-effect, and @utilize/typescript with utilize-typescript (no runtime
dependency). See Usage for the API and CLI; each package README
lists the options.
-
@utilize/json-schema β Resolves
$ref, links nodes with metadata, provides the CLI runner and compile helpers the three generators share, exports the runtime format validators generated schemas import, and the optional Ajv adapter at./validate/ajv. -
@utilize/zod β Emits Zod schemas and
z.infertypes. -
@utilize/effect β Emits Effect Schema codecs and types, with every
$refgoing throughSchema.suspend. -
@utilize/typescript β Emits interfaces and type aliases. No runtime dependency.
The badges are committed to .github/badges/ and checked in CI. Coverage is the
line coverage of each package's src, including the JSON Schema Test Suite and
the CLI entry points (coverage badges).
Conformance is the share of compatible JSON Schema Test Suite cases where every
expected result matches, with known gaps left in the denominator
(conformance badges). The
json-schema-to-typescript row measures the pinned competitor through the same
type-level runner, for a like-for-like comparison (methodology).
Regenerate both with pnpm badge:coverage and pnpm badge:suite.
Conformance badges for all five dialects
| Project | draft-04 | draft-06 | draft-07 | 2019-09 | 2020-12 |
|---|---|---|---|---|---|
@utilize/zod |
|||||
@utilize/effect |
|||||
@utilize/typescript |
|||||
json-schema-to-typescript |
import { compile as compileZod } from '@utilize/zod';
await compileZod({
input: './schema.json',
output: './schema.zod.generated.ts',
});@utilize/effect and @utilize/typescript export the same compile. All three
accept externalSchemas to serve a document from memory instead of disk or the
network; the runtime generators also take formatMode, and Zod maps individual
formats with formatMap. Each package README documents the full options.
utilize-zod schema.json schema.generated.ts
utilize-effect --input 'schemas/**/*.json' --output generated/
utilize-typescript --input 'schemas/**/*.yaml' --output generated/
cat schema.yaml | utilize-zod > schema.generated.tsThe CLIs read JSON and YAML, take a file, directory or glob, and write a file,
directory or stdout. Generated files start with a "do not edit" banner
(--no-banner omits it). The runtime CLIs also accept --format-mode,
--dialect, --fallback-dialect and --keyword-policy; see
docs/dialects.md for the dialect flags.
--validate checks every resolved document against the meta-schema of the
dialect the parser resolves, and stops before writing anything when a schema is
invalid. It needs the optional ajv package; pass --validator <module>
to use another validator instead. Draft-04 schemas also need ajv-draft-04.
See docs/dialects.md.
The playground is a browser app for editing multiple JSON
Schema files with references. Switch between the three generators, change the
keyword policy, the format mode or the TypeScript pragmatic inference,
and watch the generated code update live.
Start from one of the built-in examples: each comes with labelled valid and
invalid test documents, so you can compare the generated code with what the
validator does on the same screen.
A test-data editor below the schemas runs the selected generator's validator and
shows the decoded value, defaults included, or every issue with its JSON path;
the TypeScript target emits types only, so the pane says there is no runtime
validator.
- Hosted: https://matejbransky.github.io/utilize-schema/
- Reports: https://matejbransky.github.io/utilize-schema/reports/
- Pull requests from this repository labeled
Previewget a Vercel preview deployment.
Both runtime generators implement the validation keywords, including
$ref/$defs, allOf/anyOf/oneOf, conditionals, patternProperties and
unevaluated* (best effort). The exceptions are annotations a target cannot
enforce, such as readOnly in Effect Schema or discriminator; the full table
is in docs/keywords.md.
The TypeScript generator has no runtime, so validation keywords such as
minLength, pattern or uniqueItems have no type-level equivalent and are
ignored. Use Zod or Effect Schema when you need runtime validation.
Official-suite numbers, with every measured dialect pinned in the package baselines:
- Zod: 1,514 of 1,609 cases; draft-04, draft-06 and draft-07 are complete.
- Effect Schema: 1,510 of 1,609 cases; draft-04, draft-06 and draft-07 are complete.
- TypeScript: 192 of 285 draft-07 cases at the type level (795 of 972 instances).
The remaining runtime gaps are dynamic/recursive references, full unevaluated*
annotation propagation, and a few vocabulary/annotation cases.
- Architecture β the parser, the linker and the three generators.
- Recursive schemas β how each target expresses cycles.
- Keyword coverage β every keyword per target, the dialect rules and how the conformance numbers add up.
- Conformance comparison β how the generators compare with json-schema-to-typescript.
- TypeScript vs json-schema-to-typescript β an example-by-example look at where each generator is more precise.
- Clone the repo, run
pnpm install - Run tests:
pnpm test - Run the full check:
pnpm verify - Rebuild the hosted reports locally:
pnpm build:dev && pnpm --filter playground build && pnpm reports
Tooling: pnpm workspaces, tsdown for builds,
Vitest for tests, oxlint
and oxfmt for lint and format,
Changesets for releases, and
fallow for unused code, duplication, complexity,
dependency and architecture checks (pnpm fallow, pnpm fallow:audit).
The full guide, including changesets and release steps, is in CONTRIBUTING.md and RELEASING.md. Participation is covered by the Code of Conduct.
MIT. See LICENSE.
Inspired by json-schema-to-typescript
and the Zod community. @utilize/typescript is a
drop-in alternative to it, built on the same parser as the runtime generators.

