or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdcore-generation.mdindex.mdinput-management.mdjson-schema.mdtarget-languages.mdtype-system.mdutilities.md
tile.json

tessl/npm-quicktype-core

The quicktype engine as a library for generating strongly-typed models and serializers from JSON, JSON Schema, TypeScript, and GraphQL queries across multiple programming languages.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/quicktype-core@23.2.x

To install, run

npx @tessl/cli install tessl/npm-quicktype-core@23.2.0

index.mddocs/

quicktype-core

quicktype-core is the core TypeScript library that powers the quicktype code generation tool. It provides a comprehensive engine for generating strongly-typed models and serializers from JSON, JSON Schema, TypeScript, and GraphQL queries across multiple programming languages. The library exposes a programmatic API that allows developers to integrate quicktype's functionality into their own applications, offering fine-grained control over code generation through customizable options, target language selection, and input data processing.

Package Information

  • Package Name: quicktype-core
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install quicktype-core

Core Imports

import { 
  quicktype, 
  quicktypeMultiFile,
  InputData,
  JSONInput,
  jsonInputForTargetLanguage,
  JSONSchemaInput,
  getTargetLanguage,
  type Options 
} from "quicktype-core";

For CommonJS:

const { 
  quicktype, 
  quicktypeMultiFile,
  InputData,
  JSONInput,
  jsonInputForTargetLanguage
} = require("quicktype-core");

Basic Usage

import { quicktype, InputData, jsonInputForTargetLanguage } from "quicktype-core";

// Create input data container
const inputData = new InputData();

// Add JSON sample data  
const jsonInput = jsonInputForTargetLanguage("typescript");
await jsonInput.addSource({
  name: "Person",
  samples: ['{"name": "John", "age": 30, "active": true}']
});
inputData.addInput(jsonInput);

// Generate TypeScript code
const result = await quicktype({
  lang: "typescript",
  inputData,
  outputFilename: "Person.ts"
});

console.log(result.lines.join('\n'));

Architecture

quicktype-core is built around several key components:

  • Core Generation Engine: Primary quicktype() functions that orchestrate the entire code generation process
  • Input System: Flexible input handling supporting JSON samples, JSON Schema, and other formats
  • Type System: Comprehensive type representation with inference, transformation, and graph-based processing
  • Target Language System: Extensible rendering system supporting 20+ programming languages
  • Options & Configuration: Fine-grained control over generation behavior through options and inference flags

Capabilities

Core Code Generation

Primary functions for generating strongly-typed code from various input formats, with support for single-file and multi-file output scenarios.

function quicktype(options: Partial<Options>): Promise<SerializedRenderResult>;
function quicktypeMultiFile(options: Partial<Options>): Promise<MultiFileRenderResult>;
function quicktypeMultiFileSync(options: Partial<Options>): MultiFileRenderResult;

interface Options extends NonInferenceOptions, InferenceFlags {
  lang: string | TargetLanguage;
  inputData: InputData;
  outputFilename: string;
  rendererOptions: RendererOptions;
  alphabetizeProperties: boolean;
  allPropertiesOptional: boolean;
}

interface SerializedRenderResult {
  lines: string[];
  annotations: Annotation[];
}

type MultiFileRenderResult = ReadonlyMap<string, SerializedRenderResult>;

Core Generation

Input Data Management

Comprehensive input handling system supporting JSON samples, JSON Schema, and other data formats with flexible source management.

class InputData {
  addInput<T>(input: Input<T>): void;
  addSource<T>(kind: string, source: T, makeInput: () => Input<T>): Promise<void>;
  addSourceSync<T>(kind: string, source: T, makeInput: () => Input<T>): void;
}

function jsonInputForTargetLanguage(
  targetLanguage: string | TargetLanguage,
  languages?: TargetLanguage[],
  handleJSONRefs?: boolean
): JSONInput<string>;

interface JSONSourceData<T> {
  name: string;
  samples: T[];
  description?: string;
}

Input Management

JSON Schema Support

Dedicated support for JSON Schema input with reference resolution, schema validation, and comprehensive type attribute handling.

class JSONSchemaInput {
  constructor(
    schemaStore?: JSONSchemaStore,
    additionalAttributeProducers?: JSONSchemaAttributeProducer[],
    additionalSchemaAddresses?: readonly string[]
  );
  addSource(source: JSONSchemaSourceData): Promise<void>;
}

interface JSONSchemaSourceData {
  name: string;
  uris?: string[];
  schema?: string;
  isConverted?: boolean;
}

class Ref {
  static root(address?: string): Ref;
  static parse(ref: string): Ref;
  push(...keys: string[]): Ref;
  resolveAgainst(base?: Ref): Ref;
}

JSON Schema

Type System

Advanced type system with comprehensive type representation, inference capabilities, and graph-based type processing for accurate code generation.

abstract class Type {
  readonly kind: TypeKind;
  readonly typeRef: TypeRef;
  getChildren(): ReadonlySet<Type>;
  getAttributes(): TypeAttributes;
  getNames(): TypeNames;
  structurallyCompatible(other: Type, conflateNumbers?: boolean): boolean;
}

class TypeBuilder {
  constructor(
    stringTypeMapping: StringTypeMapping,
    canonicalOrder: boolean,
    allPropertiesOptional: boolean,
    addProvenanceAttributes: boolean,
    inheritsProvenanceAttributes: boolean
  );
  getPrimitiveType(kind: PrimitiveTypeKind, attributes?: TypeAttributes): TypeRef;
  getArrayType(attributes: TypeAttributes, items: TypeRef): TypeRef;
  getClassType(attributes: TypeAttributes, properties: ReadonlyMap<string, ClassProperty>): TypeRef;
  getEnumType(attributes: TypeAttributes, cases: ReadonlySet<string>): TypeRef;
  getUnionType(attributes: TypeAttributes, members: ReadonlySet<TypeRef>): TypeRef;
  finish(): TypeGraph;
}

type TypeKind = PrimitiveTypeKind | ObjectTypeKind | "array" | "enum" | "union" | "intersection";
type PrimitiveTypeKind = "none" | "any" | "null" | "bool" | "integer" | "double" | "string" | "date-time" | "uuid" | "uri" | "integer-string" | "bool-string";

Type System

Target Languages & Rendering

Extensible target language system supporting code generation for 20+ programming languages with customizable rendering options.

abstract class TargetLanguage {
  readonly displayName: string;
  readonly names: readonly string[];
  readonly extension: string;
  readonly stringTypeMapping: StringTypeMapping;
  readonly supportsOptionalClassProperties: boolean;
  abstract makeRenderer(renderContext: RenderContext, optionValues: RendererOptions): Renderer;
  renderGraphAndSerialize(
    typeGraph: TypeGraph,
    outputFilename: string,
    alphabetizeProperties: boolean,
    leadingComments?: Comment[],
    rendererOptions: RendererOptions,
    indentation?: string
  ): MultiFileRenderResult;
}

function getTargetLanguage(nameOrInstance: string | TargetLanguage): TargetLanguage;

Target Languages

Configuration & Options

Comprehensive configuration system with inference flags, renderer options, and debugging capabilities for fine-tuned code generation control.

interface InferenceFlags {
  inferMaps: boolean;
  inferEnums: boolean;
  inferUuids: boolean;
  inferDateTimes: boolean;
  inferIntegerStrings: boolean;
  inferBooleanStrings: boolean;
  combineClasses: boolean;
  ignoreJsonRefs: boolean;
}

const defaultInferenceFlags: InferenceFlags;
const inferenceFlags: Record<InferenceFlagName, InferenceFlag>;

class Option<Name, T> {
  definition: OptionDefinition<Name, T>;
}

interface OptionDefinition<Name, T> {
  name: Name;
  type: OptionType<T>;
  defaultValue: T;
  description: string;
  typeLabel?: string;
}

Configuration

Utilities & Support

Essential utility functions for string processing, JSON parsing, error handling, and various support operations used throughout the library.

// Core utilities
function panic(message: string): never;
function assert(condition: boolean, message?: string): void;
function defined<T>(value: T | undefined): T;
function parseJSON(text: string, description: string, address?: string): any;

// String utilities  
function splitIntoWords(str: string): string[];
function capitalize(str: string): string;
function combineWords(words: string[]): string;
function firstUpperWordStyle(words: string[]): string;
function allUpperWordStyle(words: string[]): string;
function legalizeCharacters(str: string, isLegal: (char: string) => boolean): string;

// Type utilities
function removeNullFromUnion(t: Type): Type;
function matchType<T>(t: Type, matchers: Record<TypeKind, (t: Type) => T>): T;
function nullableFromUnion(t: Type): Type | null;

Utilities