xsschema
extra-small, Standard Schema-based alternative to typeschema.
npm i xsschemaWhy xsSchema?
- Actively maintained along with xsAI.
- Support for up to libraries in the Standard Schema scope.
- Already used by xsAI (you are here), FastMCP, Airi and others.
Compare
xsschema (0.4.0-beta.3, 17KB)
- Minimum size, ESM only.
- Detailed error message with links.
- Additional types and utils. (see below)
@standard-community/standard-json (0.3.1, 96KB)
- Similar to xsSchema, but larger in size.
- Supports CommonJS.
@typeschema/main (0.14.1, 68KB)
- Lack of maintenance, with supporting libraries remaining on outdated versions.
- Support for the most schema validators.
- Not based on the Standard Schema.
Coverage
validate doesn't require manual support and works with any Standard Schema-compatible library.
Here is the list of libraries that toJsonSchema is compatible with:
| Implementer | Version(s) | Status |
|---|---|---|
Zod (zod/v4, zod/v4/mini) | v3.25+ | Supported |
Zod (zod/v3, with zod-to-json-schema) | v3.25+ | Supported |
Valibot (with @valibot/to-json-schema) | v1.0+ | Supported |
| ArkType | v2.1+ | Supported |
| Effect Schema | v3.16+ | Supported |
| Sury | v10.0+ | Supported |
Usage
If you're using xsAI, this package is a dependency of some of those packages - you don't need to install it separately.
toJsonSchema
import { } from 'arktype'
import { } from 'effect'
import * as from 'sury'
import * as from 'valibot'
import { } from 'xsschema'
import { } from 'zod'
const = ({
: 'string',
: 'number | boolean',
}).('My neat object schema')
const = await ()
const = .(
.({
: .,
: .(., .),
}).({ : 'My neat object schema' })
)
const = await ()
const = .({
: .,
: .([., .]),
}).(., { : 'My neat object schema' })
const = await ()
const = .(
.({
: .(),
: .([.(), .()]),
}),
.('My neat object schema'),
)
const = await ()
const = .({
: .(),
: .([.(), .()]),
}).('My neat object schema')
const = await ()validate
import { } from 'xsschema'
import { } from 'arktype'
import { } from 'effect'
import * as from 'sury'
import * as from 'valibot'
import * as from 'zod'
const = ("string")
const = .(.)
const = .
const = .()
const = .()
const = await (, '123')
const = await (, '123')
const = await (, '123')
const = await (, '123')
const = await (, '123')jsonSchema
Define a JSON Schema.
import { } from 'xsschema'
const = ({
: 'object',
: {
: {
: 'The unique identifier for a product',
: 'integer'
}
}
})strictJsonSchema
Define a JSON Schema and set additionalProperties to false.
import { } from 'xsschema'
const = ({
: 'object',
: {
: {
: 'The unique identifier for a product',
: 'integer'
}
}
})
// false
.(.)Types
Schema
Pre-bundled version of StandardSchemaV1 in @standard-schema/spec. You can avoid installing @standard-schema/spec to save some bulk.
JsonSchema
Pre-bundled version of JsonSchema7 in @types/json-schema. You can avoid installing @types/json-schema to save some bulk.
Infer (deprecated)
Alias for StandardSchemaV1.Infer.
InferIn (deprecated)
Alias for StandardSchemaV1.InferInput.
Errors
Missing dependencies
Some schema providers require additional packages to convert to JsonSchema.
xsschema supports a lot of vendors, so they won't and shouldn't be set as a direct dependencies, which will lead to size growth even if you don't use them.
In a nutshell:
If you use zod v3: install zod-to-json-schema
If you use valibot: install @valibot/to-json-schema
All optional peer dependencies are noted in Coverage.
Unsupported schema vendor
This means that xsschema does not yet support this vendor.
If you are interested in adding support, please make sure the library meets the following requirements (choose one of two):
- GitHub stars is greater than 100. (If the repo is not on GitHub, refer to the next entry)
- npm package has over 1000 weekly downloads.
