{"id":11175,"library":"json-schema-typed","title":"JSON Schema TypeScript Types","description":"json-schema-typed provides comprehensive TypeScript definitions for JSON Schema, including inline documentation, to facilitate type-safe schema declaration. It currently supports JSON Schema Draft 07, Draft 2019-09, and Draft 2020-12, with the main export defaulting to Draft 2020-12. The library is purely for defining schemas and does not include validation functionality; users must integrate a separate validation library. Version 8.x is the current stable release, which transitioned to a pure ESM package and introduced several breaking changes. Release cadence follows semantic versioning, with major bumps for breaking changes like updating the default draft export.","status":"active","version":"8.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/RemyRylan/json-schema-typed","tags":["javascript","jsonschema","typescript","types","definitions","json","schema"],"install":[{"cmd":"npm install json-schema-typed","lang":"bash","label":"npm"},{"cmd":"yarn add json-schema-typed","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-schema-typed","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is pure ESM since v8.0.0. Use `import type` for type-only imports for better tree-shaking.","wrong":"const { JSONSchema } = require('json-schema-typed')","symbol":"JSONSchema","correct":"import { type JSONSchema } from 'json-schema-typed'"},{"note":"Format enum is available directly from the main package export (latest draft) or specific draft paths. Ensure you are importing the correct draft's Format enum if using a non-default version.","wrong":"import { Format } from 'json-schema-typed/draft-07'","symbol":"Format","correct":"import { Format } from 'json-schema-typed'"},{"note":"Narrowed interfaces like `JSONSchema.String` are available under the `JSONSchema` namespace, not as direct named exports.","symbol":"JSONSchema.String","correct":"import { type JSONSchema } from 'json-schema-typed'; const stringSchema: JSONSchema.String = { /* ... */ };"},{"note":"For specific drafts, import directly from the subpath, e.g., 'json-schema-typed/draft-07'. The main export defaults to the latest stable draft (currently 2020-12).","symbol":"JSONSchema (Draft 07)","correct":"import { type JSONSchema } from 'json-schema-typed/draft-07'"}],"quickstart":{"code":"import { Format, type JSONSchema } from \"json-schema-typed\";\n\n// Define a schema for an object with an email property\nconst userSchema: JSONSchema = {\n  type: \"object\",\n  properties: {\n    email: {\n      format: Format.Email, // Uses the predefined Format enum for 'email' format\n      type: \"string\",\n      description: \"User's email address in a valid format.\"\n    },\n    age: {\n      type: \"integer\",\n      minimum: 0,\n      description: \"User's age, must be a non-negative integer.\"\n    }\n  },\n  required: [\"email\", \"age\"],\n  additionalProperties: false\n};\n\n// Example of a type-specific narrowed interface for a string schema\nconst usernameSchema: JSONSchema.String = {\n  type: \"string\",\n  maxLength: 50,\n  minLength: 3,\n  description: \"Username must be between 3 and 50 characters long.\"\n};\n\nconsole.log('User Schema:', JSON.stringify(userSchema, null, 2));\nconsole.log('Username Schema:', JSON.stringify(usernameSchema, null, 2));\n","lang":"typescript","description":"Demonstrates defining a JSON Schema using `JSONSchema` type and `Format` enum, including a type-specific narrowed interface."},"warnings":[{"fix":"Migrate your project to use ES Modules (ESM) syntax (`import/export`). Ensure your `package.json` has `\"type\": \"module\"` or use `.mjs` file extensions for modules importing `json-schema-typed`.","message":"Version 8.0.0 and above are pure ESM packages. CommonJS `require()` is no longer supported and will lead to errors.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Consult the package's README or documentation for the new export names. The provided export table details the updated naming conventions.","message":"Many exports were renamed in v8.0.0. Code using older export names will break.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"If you need to extend the interface directly, use `JSONSchema.Interface` which provides the previous interface definition.","message":"The `JSONSchema` type changed from an `interface` to a `type` (a mixed union allowing boolean values) in v8.0.0 to better align with the JSON Schema spec. If you were extending the `JSONSchema` interface, your code will break.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Explicitly import the desired draft using subpaths, e.g., `import { type JSONSchema } from 'json-schema-typed/draft-07'`.","message":"The main package export now points to Draft 2020-12 by default in v8.0.0. Previously it pointed to Draft 07. If your schema relies on Draft 07 behavior, the default import will now provide the wrong draft's types.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Pair `json-schema-typed` with a separate JSON Schema validation library (e.g., `ajv`, `zod-to-json-schema`, etc.) to perform actual data validation.","message":"This library only provides TypeScript definitions for JSON Schema. It does NOT include any data validation capabilities. Using it alone will not validate your data against a schema.","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":"Convert your consuming code to use ES module `import` syntax. Ensure your `package.json` includes `\"type\": \"module\"` or that your file has an `.mjs` extension.","cause":"Attempting to `require()` the `json-schema-typed` package in a CommonJS environment, but the package is pure ESM since v8.0.0.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ...json-schema-typed/dist/node/index.js from ... not supported."},{"fix":"Review the JSON Schema specification for the draft you are using (e.g., draft-2020-12, draft-07). Ensure the keyword is valid and applied correctly. Also, consider using the type-specific narrowed interfaces like `JSONSchema.String` if applicable, as they provide stricter typing for certain schema types.","cause":"Attempting to use a keyword or property that is either not part of the specified JSON Schema draft, or is defined differently in the selected draft version, or is not allowed on the base `JSONSchema` type.","error":"Property 'X' does not exist on type 'JSONSchema<...>'"},{"fix":"For v8.0.0+, ensure you are using the correct, renamed exports (e.g., `JSONSchema` for the main type) and importing from the correct path. If you need Draft 07, import from `json-schema-typed/draft-07`.","cause":"This typically occurs when trying to use an old export name, or when importing from the main package while expecting a specific draft's exports that are now only available via subpath.","error":"Cannot find name 'JSONSchema' (or 'Format', etc.)"}],"ecosystem":"npm"}