Registry / testing / tcomb-json-schema

tcomb-json-schema

JSON →
library0.3.2jsnpmunverified

Transforms a JSON Schema into a tcomb type for runtime type checking. Current stable version is 0.3.2, compatible with tcomb ^3.0.0. Released infrequently, last update in 2016. Key differentiator: bridge between JSON Schema and tcomb's type system, enabling runtime validation based on JSON schemas. Supports custom formats, custom types, and schema features like pattern, enum, and required fields.

npm install tcomb-json-schema
INSTALL
IMPORT
SIG · TCOMB-JSON-SCHEMA
T
tcomb-json-schema
testingjavascriptv0.3.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

transform
import transform from 'tcomb-json-schema'
Default export, function that converts JSON Schema to tcomb type.
transform
const transform = require('tcomb-json-schema')
const { transform } = require('tcomb-json-schema')
CommonJS usage; package is CJS, no named exports.
registerFormat
const { registerFormat } = require('tcomb-json-schema'); transform.registerFormat('email', isEmail)
import { registerFormat } from 'tcomb-json-schema'
registerFormat is a method on the default export, not a named export. ESM users need to import default then call method.

Converts a JSON schema to a tcomb type and performs validation, showing success and error cases.

const transform = require('tcomb-json-schema'); const t = require('tcomb'); const schema = { type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer', minimum: 0 }, }, required: ['name'], }; const TcombType = transform(schema); // TcombType is a tcomb struct type // Validate: const result = TcombType({ name: 'Alice', age: 30 }); console.log(result); // { name: 'Alice', age: 30 } try { TcombType({ age: -1 }); // throws: Invalid value -1 for age } catch (e) { console.error(e.message); }
Debug
Known issues
breakingUpgrade from version 0.2.5 to 0.3.0 requires tcomb ^3.0.0; tcomb 2.x is incompatible.
fix
Update tcomb to ^3.0.0 if using tcomb-json-schema ^0.3.0.
affects: >=0.3.0 <0.4.0
gotcharegisterFormat and registerType are methods on the default export, not standalone exports. Destructuring import will fail.
fix
Use const transform = require('tcomb-json-schema'); then transform.registerFormat(...).
affects: >=0.0.0
deprecatedPackage has not been updated since 2016; may not support modern tcomb or TypeScript.
fix
Consider alternatives like ajv or typebox, or validate manually.
affects: >=0.0.0
gotchaEnum as object syntax uses keys as values, not standard JSON Schema enum.
fix
Use array enum for standard behavior; object enum maps keys to values.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'tcomb'
tcomb is a peer dependency and not installed automatically.
fix
Install tcomb: npm install tcomb
TypeError: transform.registerFormat is not a function
Imported as named export instead of default export.
fix
Use const transform = require('tcomb-json-schema') and then transform.registerFormat(...)
Invalid value undefined for /name
Schema requires 'name' property but it is missing or undefined.
fix
Ensure all required properties are present: add name: 'John'
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies
tcombrequiredPeer dependency; transforms JSON schema to tcomb types
Agent activity
7 hits · last 30 days
node
6
Resources
tcomb-json-schema — npm install tcomb-json-schema · libregistry