Registry / devops / json-schema-to-valibot

json-schema-to-valibot

JSON →
library0.3.1jsnpmunverified

Convert JSON Schema definitions to Valibot schema definitions. Version 0.3.1, actively maintained. Inspired by json-schema-to-zod, this library provides both a CLI and programmatic API for converting JSON schemas (including $ref, enums, string formats, and recursive schemas) into Valibot code. Supports ESM and CJS output, optional TypeScript type generation, and extensive JSON Schema features. Differentiator: dedicated Valibot conversion with same ergonomics as json-schema-to-zod.

npm install json-schema-to-valibot
INSTALL
IMPORT
SIG · JSON-SCHEMA-TO-VAL
J
json-schema-to-valibot
devopsjavascriptv0.3.1
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.

jsonSchemaToValibot
import { jsonSchemaToValibot } from 'json-schema-to-valibot'
const jsonSchemaToValibot = require('json-schema-to-valibot')
Package is ESM-only; CommonJS require() will fail. Use import.
default import (entire module)
import * as js2v from 'json-schema-to-valibot'
No default export; use namespace import if needed.
TypeScript types
import type { JsonSchemaToValibotOptions } from 'json-schema-to-valibot'
Types are exported; import type for type-only usage.

Converts a JSON Schema object to a Valibot schema string with TypeScript types.

import { jsonSchemaToValibot } from 'json-schema-to-valibot' const jsonSchema = { type: 'object', properties: { name: { type: 'string', minLength: 1 }, age: { type: 'integer', minimum: 0 } }, required: ['name'] } const valibotCode = jsonSchemaToValibot(jsonSchema, { name: 'userSchema', module: 'esm', withTypes: true }) console.log(valibotCode) // Output: import * as v from 'valibot' // export const userSchema = v.object({...})
Debug
Known issues
gotchaCLI command 'json-schema-to-valibot' must be run via npx or installed globally.
fix
Use npx json-schema-to-valibot or install globally with npm install -g json-schema-to-valibot
affects: >=0.1.0
gotchaOutput module defaults to 'esm' which may not be compatible with older Node.js or bundlers.
fix
Use --module cjs for CommonJS output if needed.
affects: >=0.1.0
breakingVersion 0.3.0 changed default behavior of exportDefinitions from true to false? (Check release notes)
fix
Set exportDefinitions: true explicitly if you rely on exported definitions.
affects: >=0.3.0
deprecatedThe --types flag is now replaced by --with-types in newer versions.
fix
Use --with-types instead of --types.
affects: >=0.2.0
Errors
Common errors & fixes
Error: Cannot find module 'json-schema-to-valibot'
Package not installed or not in node_modules.
fix
Run 'npm install json-schema-to-valibot' or 'pnpm install json-schema-to-valibot'.
SyntaxError: Unexpected token 'export'
Using require() on an ESM-only module.
fix
Use import statement instead of require().
TypeError: jsonSchemaToValibot is not a function
Importing wrong symbol or using default import incorrectly.
fix
Use named import: import { jsonSchemaToValibot } from 'json-schema-to-valibot'
Error: Unknown module system: 'unknown', supported: esm, cjs, none
Invalid value for --module option.
fix
Use one of: esm, cjs, none
Error: Invalid JSON schema: $ref cannot be resolved.
Schema contains $ref to a definition not present in definitions or $defs.
fix
Ensure all referenced definitions are included in the schema under definitions or $defs.
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies
valibotoptionalRuntime dependency for schema validation, but this library generates code that imports valibot.
Agent activity
4 hits · last 30 days
node
4
Resources
json-schema-to-valibot — npm install json-schema-to-valibot · libregistry