{"id":49283,"library":"schema-casting","title":"schema-casting","description":"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.","status":"maintenance","version":"1.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/runk/schema-casting","tags":["javascript","json schema","json-schema","schema","normalizer","normalization"],"install":[{"cmd":"npm install schema-casting","lang":"bash","label":"npm"},{"cmd":"yarn add schema-casting","lang":"bash","label":"yarn"},{"cmd":"pnpm add schema-casting","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Library exports a single function as default. In TypeScript, use default import. For CommonJS, require returns the function directly; do not use .default.","wrong":"const cast = require('schema-casting').default","symbol":"default (cast)","correct":"import cast from 'schema-casting'"},{"note":"CommonJS require returns the function directly; named import is incorrect.","wrong":"const { cast } = require('schema-casting')","symbol":"default (require)","correct":"const cast = require('schema-casting')"},{"note":"No named exports exist. The library does not export TypeScript types.","wrong":"import { cast } from 'schema-casting'","symbol":"type imports (TypeScript)","correct":"import cast from 'schema-casting';"}],"quickstart":{"code":"const cast = require('schema-casting');\n\nconst schema = {\n  \"type\": \"object\",\n  \"properties\": {\n    \"age\": { \"type\": \"integer\" },\n    \"active\": { \"type\": \"boolean\" },\n    \"score\": { \"type\": \"number\" }\n  },\n  \"required\": [\"age\", \"active\", \"score\"],\n  \"additionalProperties\": false\n};\n\nconst input = {\n  age: '25',\n  active: 'true',\n  score: '98.7'\n};\n\nconst output = cast(schema, input);\nconsole.log(output);\n// { age: 25, active: true, score: 98.7 }","lang":"javascript","description":"Demonstrates basic type casting: strings are converted to integer, boolean, and number according to JSON Schema."},"warnings":[{"fix":"Consider using a more modern library like ajv for draft-06/07/2019-09 support.","message":"The library only supports JSON Schema draft-04 and has not been updated for later drafts.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Pre-validate with another library like ajv before casting if validation is needed.","message":"The library does not validate against the schema; it only casts types. Input must already conform to expected structure.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Explicitly set 'additionalProperties': false if you want to remove extra properties.","message":"The schema must have 'additionalProperties': false to drop extra properties; otherwise, extras are kept as-is.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid using 'type': 'null' in your schema.","message":"Type casting for 'null' type is not supported; attempting to cast null will result in an error or unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'-04':28 '2018':47 'ajv':58 'altern':56 'cadenc':41 'cast':3,9,35 'coerc':15 'compar':54 'defin':22 'depend':39,53 'differenti':48 'draft':27 'extern':38 'februari':46 'focus':31 'footprint':50 'input':17 'javascript':61 'json':6,25,62,65 'json-schema':64 'last':44 'librari':12 'lightweight':29 'like':57 'low':43 'minim':49 'normal':11,68,69 'raw':16 'releas':40 'schema':2,7,26,63,66,67 'schema-cast':1 'sole':32 'tini':5 'tv4':60 'type':8,21,34 'updat':45 'v1.3.2':13 'valu':18 'zero':52","created_at":"2026-06-07T17:00:58.840228+00:00","updated_at":"2026-06-07T17:00:58.840228+00:00","problems":[{"fix":"Use import cast from 'schema-casting' or const cast = require('schema-casting').","cause":"Using import { cast } from 'schema-casting' instead of default import.","error":"TypeError: cast is not a function"},{"fix":"Ensure schema has a top-level 'type' defined (e.g., 'object').","cause":"The schema object is malformed or missing 'type' property.","error":"Cannot read property 'type' of undefined"},{"fix":"Remove the $schema field or use a draft-04 compatible schema.","cause":"Schema uses $schema for draft-06 or later.","error":"Unsupported schema draft. Only draft-04 is supported."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/runk/schema-casting","github":"https://github.com/runk/schema-casting","docs":null,"changelog":null,"pypi":null,"npm":"schema-casting","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}