Registry / storage / schema-casting

schema-casting

JSON →
library1.3.2jsnpmunverified

A tiny JSON Schema type casting and normalization library (v1.3.2). It coerces raw input values to the types defined in a JSON Schema (draft-04). Lightweight and focused solely on type casting, with no external dependencies. Release cadence is low; last update February 2018. Differentiator: minimal footprint and zero dependencies compared to alternatives like ajv or tv4.

npm install schema-casting
INSTALL
IMPORT
SIG · SCHEMA-CASTING
S
schema-casting
storagejavascriptv1.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.

default (cast)
import cast from 'schema-casting'
const cast = require('schema-casting').default
Library exports a single function as default. In TypeScript, use default import. For CommonJS, require returns the function directly; do not use .default.
default (require)
const cast = require('schema-casting')
const { cast } = require('schema-casting')
CommonJS require returns the function directly; named import is incorrect.
type imports (TypeScript)
import cast from 'schema-casting';
import { cast } from 'schema-casting'
No named exports exist. The library does not export TypeScript types.

Demonstrates basic type casting: strings are converted to integer, boolean, and number according to JSON Schema.

const cast = require('schema-casting'); const schema = { "type": "object", "properties": { "age": { "type": "integer" }, "active": { "type": "boolean" }, "score": { "type": "number" } }, "required": ["age", "active", "score"], "additionalProperties": false }; const input = { age: '25', active: 'true', score: '98.7' }; const output = cast(schema, input); console.log(output); // { age: 25, active: true, score: 98.7 }
Debug
Known issues
deprecatedThe library only supports JSON Schema draft-04 and has not been updated for later drafts.
fix
Consider using a more modern library like ajv for draft-06/07/2019-09 support.
affects: >=1.0.0
gotchaThe library does not validate against the schema; it only casts types. Input must already conform to expected structure.
fix
Pre-validate with another library like ajv before casting if validation is needed.
affects: >=1.0.0
gotchaThe schema must have 'additionalProperties': false to drop extra properties; otherwise, extras are kept as-is.
fix
Explicitly set 'additionalProperties': false if you want to remove extra properties.
affects: >=1.0.0
gotchaType casting for 'null' type is not supported; attempting to cast null will result in an error or unexpected behavior.
fix
Avoid using 'type': 'null' in your schema.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: cast is not a function
Using import { cast } from 'schema-casting' instead of default import.
fix
Use import cast from 'schema-casting' or const cast = require('schema-casting').
Cannot read property 'type' of undefined
The schema object is malformed or missing 'type' property.
fix
Ensure schema has a top-level 'type' defined (e.g., 'object').
Unsupported schema draft. Only draft-04 is supported.
Schema uses $schema for draft-06 or later.
fix
Remove the $schema field or use a draft-04 compatible schema.
Upgrade
Version history
1.3.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
schema-casting — npm install schema-casting · libregistry