LogoLogo

Schema Benchmarks

    • home
      Home

    • download_2
      Download

    • timer
      Initialization
    • check_circle
      Validation
    • output_circle
      Parsing
    • swap_horiz
      Codec
    • schema
      Standard Schema
    • data_object
      JSON Schema
    • format_quote
      String

    • error
      Stack

    • deployed_code
      Libraries

    • article
      Blog
Expand sidebarExpand sidebar
Benchmarks/JSON SchemaJSON Schema
github
GitHubGitHub
DiscordDiscord
PreferencesPreferences

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 clipboardCopy to clipboard
const 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 clipboardCopy to clipboard
const 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
infoSupport

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.

format_quoteGenerated 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.

LibrarySourceStandard JSON SchemaDraft 2020-12
Input
Draft 2020-12
Output
Draft 07
Input
Draft 07
Output
OpenAPI 3.0
Input
OpenAPI 3.0
Output
ajvAlready JSON SchemaNonecheck
Draft 2020-12, Output is not supportedDraft 2020-12, Output is not supported
No JSON schema can be generated for the output type
check
Draft 07, Output is not supportedDraft 07, Output is not supported
No JSON schema can be generated for the output type
OpenAPI 3.0, Input is not supportedOpenAPI 3.0, Input is not supported
Unsupported JSON Schema target: openapi-3.0
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
Unsupported JSON Schema target: openapi-3.0
arktypeRuntimeNativecheckcheckcheckcheck
OpenAPI 3.0, Input is not supportedOpenAPI 3.0, Input is not supported
Unsupported JSON Schema target: openapi-3.0
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
Unsupported JSON Schema target: openapi-3.0
ata-validatorAlready JSON SchemaNonecheck
Draft 2020-12, Output is not supportedDraft 2020-12, Output is not supported
No JSON schema can be generated for the output type
check
Draft 07, Output is not supportedDraft 07, Output is not supported
No JSON schema can be generated for the output type
OpenAPI 3.0, Input is not supportedOpenAPI 3.0, Input is not supported
Unsupported JSON Schema target: openapi-3.0
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
Unsupported JSON Schema target: openapi-3.0
effectRuntimeNonecheckcheckcheckcheck
OpenAPI 3.0, Input is not supportedOpenAPI 3.0, Input is not supported
Unsupported JSON Schema target: openapi-3.0
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
Unsupported JSON Schema target: openapi-3.0
effect@betaRuntimeNonecheck
Draft 2020-12, Output is not supportedDraft 2020-12, Output is not supported
No JSON schema can be generated for the output type
Draft 07, Input is not supportedDraft 07, Input is not supported
Unsupported JSON Schema target: draft-07
Draft 07, Output is not supportedDraft 07, Output is not supported
Unsupported JSON Schema target: draft-07
OpenAPI 3.0, Input is not supportedOpenAPI 3.0, Input is not supported
Unsupported JSON Schema target: openapi-3.0
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
Unsupported JSON Schema target: openapi-3.0
joiRuntimeNone
Draft 2020-12, Input is not supportedDraft 2020-12, Input is not supported
Unsupported JSON Schema target: draft-2020-12
Draft 2020-12, Output is not supportedDraft 2020-12, Output is not supported
No JSON schema can be generated for the output type
check
Draft 07, Output is not supportedDraft 07, Output is not supported
No JSON schema can be generated for the output type
check
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
No JSON schema can be generated for the output type
suryRuntimeNative Opt incheckcheckcheckcheckcheckcheck
typeboxAlready JSON SchemaNonecheck
Draft 2020-12, Output is not supportedDraft 2020-12, Output is not supported
No JSON schema can be generated for the output type
Draft 07, Input is not supportedDraft 07, Input is not supported
Unsupported JSON Schema target: draft-07
Draft 07, Output is not supportedDraft 07, Output is not supported
Unsupported JSON Schema target: draft-07
OpenAPI 3.0, Input is not supportedOpenAPI 3.0, Input is not supported
Unsupported JSON Schema target: openapi-3.0
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
Unsupported JSON Schema target: openapi-3.0
typiaPrecompiledNonecheck
Draft 2020-12, Output is not supportedDraft 2020-12, Output is not supported
No JSON schema can be generated for the output type
Draft 07, Input is not supportedDraft 07, Input is not supported
Unsupported JSON Schema target: draft-07
Draft 07, Output is not supportedDraft 07, Output is not supported
Unsupported JSON Schema target: draft-07
check
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
No JSON schema can be generated for the output type
valibotRuntimeSeparate packagecheck
Draft 2020-12, Output is not supportedDraft 2020-12, Output is not supported
The "transform" action cannot be converted to JSON Schema.
check
Draft 07, Output is not supportedDraft 07, Output is not supported
The "transform" action cannot be converted to JSON Schema.
check
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
The "transform" action cannot be converted to JSON Schema.
zodRuntimeNativecheckcheckcheckcheckcheckcheck
zod/miniRuntimeNonecheckcheckcheckcheckcheckcheck
zod/v3RuntimeNone
Draft 2020-12, Input is not supportedDraft 2020-12, Input is not supported
Unsupported JSON Schema target: draft-2020-12
Draft 2020-12, Output is not supportedDraft 2020-12, Output is not supported
No JSON schema can be generated for the output type
check
Draft 07, Output is not supportedDraft 07, Output is not supported
No JSON schema can be generated for the output type
check
OpenAPI 3.0, Output is not supportedOpenAPI 3.0, Output is not supported
No JSON schema can be generated for the output type
Target
  • data_objectDraft 2020-12
  • data_objectDraft 07
  • apiOpenAPI 3.0
Type
  • loginInput
  • logoutOutput
LibrarysortVersionDownloads (/wk)sortSourceStandard JSON SchemaTargetTypeMeanarrow_upwardCompare
ajv
Code snippetCode snippet
{ type: "object", properties: { ... } }
Generated JSON schemaGenerated JSON schema
{
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ]
}
8.20.0350.48MAlready JSON SchemaNoneDraft 07Input0
n/a
ata-validator
Code snippetCode snippet
t.object({ ... })
Generated JSON schemaGenerated JSON schema
{
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ]
}
1.2.2979Already JSON SchemaNoneDraft 07Input0
n/a
arktype
Code snippetCode snippet
schema.out.toJsonSchema({ target: "draft-07" })
Generated JSON schemaGenerated JSON schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "number"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ]
}
2.2.31.39MRuntimeNativeDraft 07Output515 ns
arktype
Code snippetCode snippet
schema.in.toJsonSchema({ target: "draft-07" })
Generated JSON schemaGenerated JSON schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ]
}
2.2.31.39MRuntimeNativeDraft 07Input516 ns
1x
stat_minus_1
valibot
Code snippetCode snippet
toJsonSchema(schema, { target: "draft-07", typeMode: "input" })
Generated JSON schemaGenerated JSON schema
{
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ],
  "$schema": "http://json-schema.org/draft-07/schema#"
}
1.4.215.65MRuntimeSeparate packageDraft 07Input919 ns
1.78x
stat_minus_1
sury
Code snippetCode snippet
S.toJSONSchema(S.reverse(schema), { target: "draft-07" })
Generated JSON schemaGenerated JSON schema
{
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "number"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ],
  "$schema": "http://json-schema.org/draft-07/schema#"
}
11.0.0-alpha.11291.77KRuntimeNative Opt inDraft 07Output2 μs
3.65x
stat_minus_1
sury
Code snippetCode snippet
S.toJSONSchema(schema, { target: "draft-07" })
Generated JSON schemaGenerated JSON schema
{
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ],
  "$schema": "http://json-schema.org/draft-07/schema#"
}
11.0.0-alpha.11291.77KRuntimeNative Opt inDraft 07Input2 μs
3.78x
stat_minus_1
effect
Code snippetCode snippet
JSONSchema.make(schema, { target: "jsonSchema7" })
Generated JSON schemaGenerated JSON schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$defs": {
    "NumberFromString": {
      "type": "string",
      "description": "a string to be decoded into a number"
    }
  },
  "type": "object",
  "required": [
    "id",
    "name",
    "price"
  ],
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "$ref": "#/$defs/NumberFromString"
    }
  },
  "additionalProperties": false
}
3.22.026.02MRuntimeNoneDraft 07Input3 μs
5.95x
stat_minus_1
zod/v3
Code snippetCode snippet
zodToJsonSchema(schema, { target: "jsonSchema7" })
Generated JSON schemaGenerated JSON schema
{
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ],
  "additionalProperties": false,
  "$schema": "http://json-schema.org/draft-07/schema#"
}
4.4.3240.5MRuntimeNoneDraft 07Input6 μs
11.61x
stat_minus_1
zod
Code snippetCode snippet
z.toJSONSchema(schema, { target: "draft-07", io: "output" })
Generated JSON schemaGenerated JSON schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "number"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ],
  "additionalProperties": false
}
4.4.3240.5MRuntimeNativeDraft 07Output7 μs
14.34x
stat_minus_1
zod/mini
Code snippetCode snippet
z.toJSONSchema(schema, { target: "draft-07", io: "output" })
Generated JSON schemaGenerated JSON schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "number"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ],
  "additionalProperties": false
}
4.4.3240.5MRuntimeNoneDraft 07Output8 μs
14.75x
stat_minus_1
zod
Code snippetCode snippet
z.toJSONSchema(schema, { target: "draft-07", io: "input" })
Generated JSON schemaGenerated JSON schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ]
}
4.4.3240.5MRuntimeNativeDraft 07Input9 μs
17.82x
stat_minus_1
zod/mini
Code snippetCode snippet
z.toJSONSchema(schema, { target: "draft-07", io: "input" })
Generated JSON schemaGenerated JSON schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ]
}
4.4.3240.5MRuntimeNoneDraft 07Input9 μs
18.36x
stat_minus_1
effect
Code snippetCode snippet
JSONSchema.make(Schema.typeSchema(schema), { target: "jsonSchema7" })
Generated JSON schemaGenerated JSON schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [
    "id",
    "name",
    "price"
  ],
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "number"
    }
  },
  "additionalProperties": false
}
3.22.026.02MRuntimeNoneDraft 07Output9 μs
18.44x
stat_minus_1
joi
Code snippetCode snippet
parse(schema, "json")
Generated JSON schemaGenerated JSON schema
{
  "type": "object",
  "properties": {
    "id": {
      "type": "number"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "price"
  ],
  "additionalProperties": false
}
18.2.323.69MRuntimeNoneDraft 07Input85 μs
165.06x
stat_minus_3
Created by eskimojo for Open Circle

Preferences

Style
Theme
NPM browser
Code ligatures