
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
@valibot/to-json-schema
Advanced tools
Utility to convert Valibot schemas to JSON schema (draft 07).
import { toJsonSchema } from '@valibot/to-json-schema';
import * as v from 'valibot';
toJsonSchema(v.string()); // { type: "string" }
Some Valibot features can't be mapped to JSON schema. For example, transformation actions have no equivalent in JSON schema. Also, some Valibot schemas or validations are too JS-specific and do not have an equivalent JSON schema attribute.
Note: Converted schemas may behave slightly differently in JSON schema validators (especially for string format) because their implementation is different from Valibot's.
| Schema | Status | Note |
|---|---|---|
any | ✅ | |
array | ✅ | |
boolean | ✅ | |
enum | ✅ | |
exactOptional | ✅ | |
intersect | ✅ | |
lazy | ⚠️ | The .getterfunction is always executed with undefined as input |
literal | ⚠️ | Only JSON compatible values are supported |
looseObject | ✅ | |
looseTuple | ✅ | |
null | ✅ | |
nullable | ✅ | |
nullish | ✅ | |
number | ✅ | |
objectWithRest | ✅ | |
object | ✅ | |
optional | ✅ | |
picklist | ⚠️ | Only JSON compatible values are supported |
record | ⚠️ | Only plain string schemas for the key of the record are supported |
strictObject | ✅ | |
strictTuple | ✅ | |
string | ✅ | |
tupleWithRest | ✅ | |
tuple | ✅ | |
union | ✅ | |
undefinedable | ✅ | |
unknown | ✅ | |
variant | ⚠️ | The discriminator key will be ignored |
| Actions | Status | Note |
|---|---|---|
base64 | ✅ | |
bic | ✅ | |
description | ✅ | |
cuid2 | ✅ | |
email | ✅ | |
emoji | ✅ | |
empty | ✅ | |
entries | ✅ | |
decimal | ✅ | |
digits | ✅ | |
hexadecimal | ✅ | |
hexColor | ✅ | |
integer | ✅ | |
ipv4 | ✅ | |
ipv6 | ✅ | |
isoDate | ✅ | |
isoDateTime | ✅ | |
isoTime | ✅ | |
isoTimestamp | ✅ | |
length | ⚠️ | Only in combination with string and array schema |
metadata | ⚠️ | Only for valid title, description and examples values |
maxEntries | ✅ | |
maxLength | ⚠️ | Only in combination with string and array schema |
maxValue | ⚠️ | Only in combination with number schema |
minEntries | ✅ | |
minLength | ⚠️ | Only in combination with string and array schemas |
minValue | ⚠️ | Only in combination with number schema |
multipleOf | ✅ | |
nanoid | ✅ | |
nonEmpty | ✅ | |
octal | ✅ | |
regex | ⚠️ | RexExp flags are not supported in JSON schema |
title | ✅ | |
ulid | ✅ | |
url | ✅ | |
uuid | ✅ | |
value | ✅ |
| Option | Type | Note |
|---|---|---|
| errorMode | 'throw' | 'warn' | 'ignore' | The policy for handling incompatible schemas and actions. |
| definitions | Record<string, GenericSchema> | The schema definitions for constructing recursive schemas. If not specified, the definitions are generated automatically. |
The errorMode configuration controls how the converter handles unsupported schemas and actions. By default, the error mode is set to 'throw'. To force the conversion of unsupported Valibot features, you can set it to 'ignore'.
Unsupported schemas usually return an empty JSON schema (
{}) and unsupported actions are usually ignored.
import { toJsonSchema } from '@valibot/to-json-schema';
import * as v from 'valibot';
toJsonSchema(v.file(), { errorMode: 'ignore' }); // {}
toJsonSchema(v.pipe(v.string(), v.creditCard()), { errorMode: 'ignore' }); // { type: "string" }
Nested schemas can be broken in multiple named definitions.
import { toJsonSchema } from '@valibot/to-json-schema';
import * as v from 'valibot';
const EmailSchema = v.pipe(v.string(), v.email());
toJsonSchema(v.object({ email: EmailSchema }), {
definitions: { EmailSchema },
});
/*
{
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
properties: {
email: {
$ref: "#/$defs/EmailSchema",
},
},
required: ["email"],
additionalProperties: false,
$defs: {
EmailSchema: {
type: "string",
format: "email",
},
},
}
*/
Definitions are not required for converting lazy schemas. Missing definitions will be generated automatically.
import { toJsonSchema } from '@valibot/to-json-schema';
import * as v from 'valibot';
const StringSchema = v.string();
toJsonSchema(v.object({ key: v.lazy(() => StringSchema) }));
/*
{
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
properties: {
key: {
$ref: "#/$defs/0",
},
},
required: ["key"],
additionalProperties: false,
$defs: {
"0": {
type: "string",
},
},
}
*/
FAQs
The official JSON schema converter for Valibot
The npm package @valibot/to-json-schema receives a total of 56,836 weekly downloads. As such, @valibot/to-json-schema popularity was classified as popular.
We found that @valibot/to-json-schema demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.