{"id":12738,"library":"json-schema-to-typescript-lite","title":"JSON Schema to TypeScript (Lite)","description":"json-schema-to-typescript-lite is a focused fork of json-schema-to-typescript, designed to compile JSON schemas into TypeScript typings with a significantly reduced dependency footprint. The current stable version is 15.0.0. This package emphasizes programmatic usage, foregoing CLI support and internal Prettier integrations for a leaner build. It achieves smaller bundle sizes by replacing heavy dependencies like `lodash` with `lodash-es` (bundled) and targets modern ESNext environments. It offers dual module support (ESM and CJS) and includes support for custom naming options, making it suitable for environments where bundle size and minimal dependencies are critical considerations.","status":"active","version":"15.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/bcherny/json-schema-to-typescript","tags":["javascript","json","schema","typescript","compile","transpile","api","interface","typing"],"install":[{"cmd":"npm install json-schema-to-typescript-lite","lang":"bash","label":"npm"},{"cmd":"yarn add json-schema-to-typescript-lite","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-schema-to-typescript-lite","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary function for compiling a JSON schema to a TypeScript string. Supports both ESM and CJS, but ESM import is preferred in modern Node.js/browser environments.","wrong":"const compile = require('json-schema-to-typescript-lite');","symbol":"compile","correct":"import { compile } from 'json-schema-to-typescript-lite';"},{"note":"The 'compile' function is a named export, not a default export.","wrong":"import compile from 'json-schema-to-typescript-lite';","symbol":"compile (default import incorrect)","correct":"import { compile } from 'json-schema-to-typescript-lite';"},{"note":"While `Options` and schema types are available for type hinting, they are not always explicitly imported for basic usage.","symbol":"Type definitions","correct":"import type { JSONSchema4, Options } from 'json-schema-to-typescript-lite';"}],"quickstart":{"code":"import { compile } from 'json-schema-to-typescript-lite';\n\nasync function generateUserTypes() {\n  const userSchema = {\n    type: 'object',\n    properties: {\n      id: { type: 'string', description: 'Unique user identifier' },\n      name: { type: 'string', minLength: 1 },\n      email: { type: 'string', format: 'email' },\n      age: { type: 'number', minimum: 0, maximum: 120 },\n      isActive: { type: 'boolean', default: true },\n      roles: {\n        type: 'array',\n        items: { type: 'string', enum: ['admin', 'editor', 'viewer'] },\n        minItems: 1\n      }\n    },\n    required: ['id', 'name', 'email', 'isActive'],\n    additionalProperties: false,\n    title: 'UserSchema', // Used as base name if not overridden by second arg\n    description: 'Defines the structure for a user object.'\n  };\n\n  try {\n    const tsDefinition = await compile(userSchema, 'IUser', {\n      bannerComment: '/* Generated by json-schema-to-typescript-lite */',\n      declareExternallyReferenced: false,\n      unknownAny: false, // Prefer 'unknown' over 'any'\n      customName: (id: string) => id === 'IUser' ? 'MyCustomUserType' : id,\n    });\n    console.log(tsDefinition);\n  } catch (error) {\n    console.error('Failed to compile schema:', error);\n  }\n}\n\ngenerateUserTypes().catch(console.error);","lang":"typescript","description":"Demonstrates basic usage of `compile` to convert a JSON schema object into a TypeScript interface string, including common options."},"warnings":[{"fix":"Migrate any CLI usage to direct programmatic calls to the `compile` function within your build scripts or application.","message":"CLI support has been completely removed. This package is strictly for programmatic usage.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Run Prettier as a separate step on the generated TypeScript output if custom formatting is necessary.","message":"Internal Prettier integration has been removed. The package now generates well-formatted code by default, but external formatting is required if specific Prettier rules are desired.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Review your project's dependencies and explicitly add any external libraries that were implicitly provided by the non-lite version.","message":"Dependencies like `lodash` have been replaced with lighter alternatives or bundled (`lodash-es`). While improving bundle size, this means any explicit dependency on these from the original `json-schema-to-typescript` will no longer be satisfied by this 'lite' fork.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Thoroughly test your schema compilation output when migrating from `json-schema-to-typescript` to `json-schema-to-typescript-lite`.","message":"This is a 'lite' fork. While it aims for similar core functionality, subtle behavioral differences might exist due to dependency changes or optimizations not present in the main `json-schema-to-typescript` package.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the package is installed: `npm install json-schema-to-typescript-lite` or `yarn add json-schema-to-typescript-lite`. Verify the import statement is `import { compile } from 'json-schema-to-typescript-lite';`.","cause":"The package is not installed or the import path is incorrect.","error":"Error: Cannot find module 'json-schema-to-typescript-lite'"},{"fix":"Review your JSON schema against the specification. Common issues include incorrect `type` definitions, missing `properties` or `items` for array/object types, or invalid keywords.","cause":"The provided JSON schema is not a valid JSON Schema Draft 04/06/07.","error":"Schema validation failed"},{"fix":"Ensure the first argument passed to `compile` is a valid, non-null JSON schema object.","cause":"You likely passed an `undefined` or `null` value instead of a valid JSON schema object to the `compile` function.","error":"TypeError: Cannot read properties of undefined (reading 'type')"}],"ecosystem":"npm"}