Codegen

April 21, 2026 ยท View on GitHub

jsonschema codegen <schema.json|.yaml> --target/-t <target> [--name/-n <name>]
  [--json/-j] [--verbose/-v] [--debug/-g]
  [--resolve/-r <schemas-or-directories>]
  [--default-dialect/-d <uri>]

JSON Schema is a declarative language for defining the structure of JSON data. The JSON Schema CLI offers a codegen command that generates type definitions from a JSON Schema, allowing you to use the schema as a source of truth for your application's data types.

This command is experimental. We are actively working on this functionality and things might break or change without notice. We are actively seeking feedback to make this better. Please open an issue at https://github.com/sourcemeta/jsonschema/issues with any problems you find.

Warning

This command currently only supports JSON Schema 2020-12 and TypeScript as a target language. We will extend support to other programming languages and dialects once we make the foundations stable.

Keyword Support

Not every JSON Schema keyword maps directly to type system constructs. This implementation aims to provide complete structural typing, and you are expected to use a JSON Schema validator at runtime to enforce remaining constraints.

VocabularyKeywordTypeScript
Core (2020-12)$schemaYes
Core (2020-12)$idYes
Core (2020-12)$refYes
Core (2020-12)$defsYes
Core (2020-12)$anchorYes
Core (2020-12)$dynamicAnchorYes
Core (2020-12)$dynamicRefYes
Core (2020-12)$vocabularyIgnored
Core (2020-12)$commentIgnored
Applicator (2020-12)propertiesYes
Applicator (2020-12)additionalPropertiesPartial (language limitations)
Applicator (2020-12)itemsYes
Applicator (2020-12)prefixItemsYes
Applicator (2020-12)anyOfYes
Applicator (2020-12)patternPropertiesPartial (language limitations)
Applicator (2020-12)propertyNamesIgnored
Applicator (2020-12)dependentSchemasPending
Applicator (2020-12)containsIgnored
Applicator (2020-12)allOfYes
Applicator (2020-12)oneOfPartial (language limitations)
Applicator (2020-12)notCannot support
Applicator (2020-12)ifPartial (language limitations)
Applicator (2020-12)thenPartial (language limitations)
Applicator (2020-12)elsePartial (language limitations)
Validation (2020-12)typeYes
Validation (2020-12)enumYes
Validation (2020-12)requiredYes
Validation (2020-12)constYes
Validation (2020-12)minLengthIgnored
Validation (2020-12)maxLengthIgnored
Validation (2020-12)patternIgnored
Validation (2020-12)minimumIgnored
Validation (2020-12)maximumIgnored
Validation (2020-12)exclusiveMinimumIgnored
Validation (2020-12)exclusiveMaximumIgnored
Validation (2020-12)multipleOfIgnored
Validation (2020-12)minPropertiesIgnored
Validation (2020-12)maxPropertiesIgnored
Validation (2020-12)dependentRequiredPending
Validation (2020-12)minItemsIgnored
Validation (2020-12)maxItemsIgnored
Validation (2020-12)minContainsIgnored
Validation (2020-12)maxContainsIgnored
Validation (2020-12)uniqueItemsIgnored
Unevaluated (2020-12)unevaluatedItemsPending
Unevaluated (2020-12)unevaluatedPropertiesPending
Meta-Data (2020-12)titleIgnored
Meta-Data (2020-12)descriptionIgnored
Meta-Data (2020-12)defaultIgnored
Meta-Data (2020-12)deprecatedIgnored
Meta-Data (2020-12)examplesIgnored
Meta-Data (2020-12)readOnlyIgnored
Meta-Data (2020-12)writeOnlyIgnored
Format Annotation (2020-12)formatIgnored
Format Assertion (2020-12)formatIgnored
Content (2020-12)contentEncodingIgnored
Content (2020-12)contentMediaTypeIgnored
Content (2020-12)contentSchemaIgnored

Examples

For example, consider the following schema that describes a person:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer" }
  },
  "required": [ "name" ]
}

The codegen command will generate the following TypeScript types:

export type PersonName = string;

export type PersonAge = number;

export interface Person {
  "name": PersonName;
  "age"?: PersonAge;
  [key: string]: unknown | undefined;
}

Generate TypeScript types from a JSON Schema

jsonschema codegen path/to/my/schema.json --target typescript

Generate TypeScript types with a custom type name prefix

By default, generated types use Schema as the prefix. You can specify a custom prefix using the --name/-n option:

jsonschema codegen path/to/my/schema.json --target typescript --name Person

Output the generated code as JSON

jsonschema codegen path/to/my/schema.json --target typescript --json