Registry / devops / ut-joi

ut-joi

JSON →
library1.4.11jsnpmunverified

Converts Joi validation schemas to JSON Schema. Supports multiple Joi versions (including @commercial/joi, @hapi/joi, and joi itself) across versions 12 through 17. The last release (1.4.11) appears to be from 2021. It is a fork/continuation of the earlier joi-to-json package, aiming to provide broader version compatibility and maintenance. It converts Joi objects into standard JSON Schema format, enabling interoperability with tools that expect JSON Schema.

npm install ut-joi
INSTALL
IMPORT
SIG · UT-JOI
U
ut-joi
devopsjavascriptv1.4.11
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.

convert
const convert = require('ut-joi')
import { convert } from 'ut-joi'
Package is CommonJS only; does not support ESM imports.
convert (default)
const convert = require('ut-joi')
import convert from 'ut-joi'
Default export is the convert function. ESM dynamic import may work but is not officially supported.
convert (with options)
const convert = require('ut-joi'); convert(schema, options);
Options object can be passed as second argument, e.g., { strict: true }.

Converts a Joi object schema to JSON Schema, working with @hapi/joi v17.

const Joi = require('@hapi/joi'); const convert = require('ut-joi'); const schema = Joi.object({ name: Joi.string().min(3).max(30).required(), email: Joi.string().email().required(), age: Joi.number().integer().min(0).max(150), }); const jsonSchema = convert(schema); console.log(JSON.stringify(jsonSchema, null, 2)); /* Output: { "type": "object", "properties": { "name": { "type": "string", "minLength": 3, "maxLength": 30 }, "email": { "type": "string", "format": "email" }, "age": { "type": "integer", "minimum": 0, "maximum": 150 } }, "required": ["name", "email"] } */
Debug
Known issues
deprecatedPackage is largely abandoned; last release in 2021. Consider using joi-to-json or joi-to-json-schema for newer Joi versions.
fix
Migrate to an actively maintained converter like 'joi-to-json' (v2+) if using Joi >= 17.
affects: >=1.0.0
breakingOnly supports Joi up to v17; may not work with Joi v18+ (class-based types).
fix
Use a library that supports Joi v18+ or continue using Joi v17.
affects: >=1.0.0
gotchaThe dependency 'lodash' is required but not listed as a peer dependency; may cause issues if not installed.
fix
Ensure lodash is installed: npm install lodash
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'type' of undefined
Passing a Joi schema from an unsupported version (e.g., Joi v18 with @hapi/joi internals).
fix
Use a supported Joi version (e.g., @hapi/joi 17).
Error: Unknown joi type: alternatives
The conversion does not support Joi.alternatives() schemas.
fix
Replace alternatives with a different approach or use a different converter like 'joi-to-json-schema'.
TypeError: joi.describe is not a function
The input is not a valid Joi schema object.
fix
Ensure you call convert on a Joi schema, not on the Joi module itself.
Upgrade
Version history
1.4.11latest on npm
Audit
Dependencies
lodashrequiredUsed for object manipulation and deep cloning
Agent activity
6 hits · last 30 days
node
6
Resources
packageut-joi
ut-joi — npm install ut-joi · libregistry