Registry / testing / json-schema-yup-transformer

json-schema-yup-transformer

JSON →
library1.6.12jsnpmunverified

Transforms a Draft 7 JSON Schema into a Yup validation schema. Current stable version is 1.6.12, with low release cadence. It supports most Draft 7 keywords including string formats (date-time, email, ipv4, etc.), numeric constraints, array items/tuples, and object properties. Differentiates from schema-to-yup by strictly adhering to the Draft 7 specification. Note: only supports yup v0.29.3 and below; newer yup versions may break.

npm install json-schema-yup-transformer
INSTALL
IMPORT
SIG · JSON-SCHEMA-YUP-TR
J
json-schema-yup-transformer
testingjavascriptv1.6.12
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
import jsonSchemaToYup from 'json-schema-yup-transformer'
const jsonSchemaToYup = require('json-schema-yup-transformer').default
Package exports a default export. CommonJS require may need .default.
converters
import { converters } from 'json-schema-yup-transformer'
import { convert } from 'json-schema-yup-transformer'
Named export 'converters' is a map of type converters.
errors
import { errors } from 'json-schema-yup-transformer'
import { JsonSchemaError } from 'json-schema-yup-transformer'
Named export 'errors' contains custom error types like InvalidSchemaError.

Converts a JSON Schema to a Yup schema and validates an object. Shows basic object property conversion and requirement handling.

import yup from 'yup'; import jsonSchemaToYup from 'json-schema-yup-transformer'; const jsonSchema = { type: 'object', properties: { name: { type: 'string', minLength: 2 }, age: { type: 'integer', minimum: 0 }, }, required: ['name'], }; const yupSchema = jsonSchemaToYup(jsonSchema); // Now use yupSchema like any Yup schema: yupSchema.validate({ name: 'Alice', age: 30 }).then(() => console.log('valid')); yupSchema.validate({ name: 'A', age: -1 }).catch(err => console.error(err.errors));
Debug
Known issues
breakingOnly supports yup v0.29.3 and below. Using with newer yup versions may cause runtime errors or incorrect validation.
fix
Pin yup to v0.29.3: 'yup': '0.29.3'
affects: >=0.30.0 of yup
gotchaThe package does not support JSON Schema 'definitions' or '$ref' for referencing other schemas.
fix
Manually inline all definitions before passing the schema.
affects: *
gotchaBoolean type only supports 'const' keyword; other keywords are ignored.
fix
Avoid using boolean with enum or other keywords.
affects: *
Errors
Common errors & fixes
yup is not a constructor
Using yup v0.30+ which changed class export
fix
Downgrade to yup@0.29.3
Cannot read property 'type' of undefined
JSON Schema missing 'type' keyword at root
fix
Ensure root schema has 'type' property
Unsupported schema format: 'iri'
Format not implemented
fix
Avoid using 'iri' or 'iri-reference' formats
Upgrade
Version history
1.6.12latest on npm
Audit
Dependencies
yuprequiredPeer dependency; only supports yup v0.29.3 and below
Agent activity
8 hits · last 30 days
node
6
Resources
json-schema-yup-transformer — npm install json-schema-yup-transformer · libregistry