Many libraries can convert a schema into a JSON Schema, so it can be consumed by anything that speaks JSON Schema - documentation generators, OpenAPI builders, LLM structured outputs.
We benchmark whichever API the library provides for it, using a small schema with a codec:
Copy to clipboardconst schema = z.object({ id: z.number(), name: z.string(), price: z.codec(z.string(), z.number(), { decode: Number, encode: String }), });
Because of the codec, the input and output types differ (price is a string going in, a number coming out), and so do their JSON schemas.
The source column says where the JSON schema comes from - not every library has to do work for it:
- Runtime - the library converts the schema when asked, which is what's timed
- Precompiled - it's generated at build time, so there's nothing left to do at runtime
- Already JSON Schema - the library's schemas are JSON Schema, so there's nothing to convert
The last two are constants, so they're reported as 0 rather than timed - benchmarking a property
read would measure the harness, not the library.
Standard JSON Schema
Some libraries also implement the Standard JSON Schema interface, which lets a tool generate a JSON schema without specialising for each library:
Copy to clipboardconst jsonSchema = personSchema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
The Standard JSON Schema column shows how each library supports it:
- Native - the library implements it
- Native Opt in - implemented, but it has to be enabled first (
S.enableStandardJSONSchema()) - Separate package - a separate package implements it (
@valibot/to-json-schema) - None - nothing implements it, so the library's own API is benchmarked
Support
A library is expected to throw for anything it can't convert, so a refused combination has no result to compare - hover the cross in the matrix to see why the library refused.
Generated schemas
Every generated schema is checked against the data it describes, but libraries don't agree on what a JSON schema for the same type looks like - each result links to what its library generated.
| Library | Source | Standard JSON Schema | Draft 2020-12 Input | Draft 2020-12 Output | Draft 07 Input | Draft 07 Output | OpenAPI 3.0 Input | OpenAPI 3.0 Output |
|---|---|---|---|---|---|---|---|---|
ajv | Already JSON Schema | None | check | Draft 2020-12, Output is not supportedNo JSON schema can be generated for the output type | check | Draft 07, Output is not supportedNo JSON schema can be generated for the output type | OpenAPI 3.0, Input is not supportedUnsupported JSON Schema target: openapi-3.0 | OpenAPI 3.0, Output is not supportedUnsupported JSON Schema target: openapi-3.0 |
arktype | Runtime | Native | check | check | check | check | OpenAPI 3.0, Input is not supportedUnsupported JSON Schema target: openapi-3.0 | OpenAPI 3.0, Output is not supportedUnsupported JSON Schema target: openapi-3.0 |
ata-validator | Already JSON Schema | None | check | Draft 2020-12, Output is not supportedNo JSON schema can be generated for the output type | check | Draft 07, Output is not supportedNo JSON schema can be generated for the output type | OpenAPI 3.0, Input is not supportedUnsupported JSON Schema target: openapi-3.0 | OpenAPI 3.0, Output is not supportedUnsupported JSON Schema target: openapi-3.0 |
effect | Runtime | None | check | check | check | check | OpenAPI 3.0, Input is not supportedUnsupported JSON Schema target: openapi-3.0 | OpenAPI 3.0, Output is not supportedUnsupported JSON Schema target: openapi-3.0 |
effect@beta | Runtime | None | check | Draft 2020-12, Output is not supportedNo JSON schema can be generated for the output type | Draft 07, Input is not supportedUnsupported JSON Schema target: draft-07 | Draft 07, Output is not supportedUnsupported JSON Schema target: draft-07 | OpenAPI 3.0, Input is not supportedUnsupported JSON Schema target: openapi-3.0 | OpenAPI 3.0, Output is not supportedUnsupported JSON Schema target: openapi-3.0 |
joi | Runtime | None | Draft 2020-12, Input is not supportedUnsupported JSON Schema target: draft-2020-12 | Draft 2020-12, Output is not supportedNo JSON schema can be generated for the output type | check | Draft 07, Output is not supportedNo JSON schema can be generated for the output type | check | OpenAPI 3.0, Output is not supportedNo JSON schema can be generated for the output type |
sury | Runtime | Native Opt in | check | check | check | check | check | check |
typebox | Already JSON Schema | None | check | Draft 2020-12, Output is not supportedNo JSON schema can be generated for the output type | Draft 07, Input is not supportedUnsupported JSON Schema target: draft-07 | Draft 07, Output is not supportedUnsupported JSON Schema target: draft-07 | OpenAPI 3.0, Input is not supportedUnsupported JSON Schema target: openapi-3.0 | OpenAPI 3.0, Output is not supportedUnsupported JSON Schema target: openapi-3.0 |
typia | Precompiled | None | check | Draft 2020-12, Output is not supportedNo JSON schema can be generated for the output type | Draft 07, Input is not supportedUnsupported JSON Schema target: draft-07 | Draft 07, Output is not supportedUnsupported JSON Schema target: draft-07 | check | OpenAPI 3.0, Output is not supportedNo JSON schema can be generated for the output type |
valibot | Runtime | Separate package | check | Draft 2020-12, Output is not supportedThe "transform" action cannot be converted to JSON Schema. | check | Draft 07, Output is not supportedThe "transform" action cannot be converted to JSON Schema. | check | OpenAPI 3.0, Output is not supportedThe "transform" action cannot be converted to JSON Schema. |
zod | Runtime | Native | check | check | check | check | check | check |
zod/mini | Runtime | None | check | check | check | check | check | check |
zod/v3 | Runtime | None | Draft 2020-12, Input is not supportedUnsupported JSON Schema target: draft-2020-12 | Draft 2020-12, Output is not supportedNo JSON schema can be generated for the output type | check | Draft 07, Output is not supportedNo JSON schema can be generated for the output type | check | OpenAPI 3.0, Output is not supportedNo JSON schema can be generated for the output type |
| Library | Version | Downloads (/wk) | Source | Standard JSON Schema | Target | Type | Mean | Compare | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ata-validator | Code snippet | Generated JSON schema | 1.2.2 | 979 | Already JSON Schema | None | Draft 07 | Input | 0 | n/a | |||
sury | Code snippet | Generated JSON schema | 11.0.0-alpha.11 | 291.77K | Runtime | Native Opt in | Draft 07 | Output | 2 μs | ||||
sury | Code snippet | Generated JSON schema | 11.0.0-alpha.11 | 291.77K | Runtime | Native Opt in | Draft 07 | Input | 2 μs | 1.03x | |||
arktype | Code snippet | Generated JSON schema | 2.2.3 | 1.39M | Runtime | Native | Draft 07 | Output | 515 ns | 3.65x | |||
arktype | Code snippet | Generated JSON schema | 2.2.3 | 1.39M | Runtime | Native | Draft 07 | Input | 516 ns | 3.65x | |||
valibot | Code snippet | Generated JSON schema | 1.4.2 | 15.65M | Runtime | Separate package | Draft 07 | Input | 919 ns | 2.05x | |||
joi | Code snippet | Generated JSON schema | 18.2.3 | 23.69M | Runtime | None | Draft 07 | Input | 85 μs | 45.21x | |||
effect | Code snippet | Generated JSON schema | 3.22.0 | 26.02M | Runtime | None | Draft 07 | Input | 3 μs | 1.63x | |||
effect | Code snippet | Generated JSON schema | 3.22.0 | 26.02M | Runtime | None | Draft 07 | Output | 9 μs | 5.05x | |||
zod | Code snippet | Generated JSON schema | 4.4.3 | 240.5M | Runtime | Native | Draft 07 | Output | 7 μs | 3.93x | |||
zod | Code snippet | Generated JSON schema | 4.4.3 | 240.5M | Runtime | Native | Draft 07 | Input | 9 μs | 4.88x | |||
zod/mini | Code snippet | Generated JSON schema | 4.4.3 | 240.5M | Runtime | None | Draft 07 | Output | 8 μs | 4.04x | |||
zod/mini | Code snippet | Generated JSON schema | 4.4.3 | 240.5M | Runtime | None | Draft 07 | Input | 9 μs | 5.03x | |||
zod/v3 | Code snippet | Generated JSON schema | 4.4.3 | 240.5M | Runtime | None | Draft 07 | Input | 6 μs | 3.18x | |||
ajv | Code snippet | Generated JSON schema | 8.20.0 | 350.48M | Already JSON Schema | None | Draft 07 | Input | 0 | n/a | |||