Skip to content

Add a JSON Schema benchmark case - #186

Open
DZakh wants to merge 3 commits into
open-circle:mainfrom
DZakh-forks:claude/standard-json-schema-case-u62fx5
Open

Add a JSON Schema benchmark case#186
DZakh wants to merge 3 commits into
open-circle:mainfrom
DZakh-forks:claude/standard-json-schema-case-u62fx5

Conversation

@DZakh

@DZakh DZakh commented Jul 26, 2026

Copy link
Copy Markdown

Benchmarks generating a JSON schema from a schema, through whichever API each library provides for it, on a new /json-schema page.

Standard JSON Schema is a column here, not the case itself — most libraries that can emit a JSON schema don't implement the interface, and leaving them out would have made the page look far emptier than reality.

What's measured

  • A small schema with a codec, so both directions are worth generating
    • { id: number, name: string, price: string ↔ number }
    • input describes price as a string, output as a number
    • no Date — it has no JSON schema representation, and sury and effect refuse to convert it at all
  • Every target × direction combination
    • targets: draft-2020-12, draft-07, openapi-3.0
    • a library is expected to throw for anything it can't convert, so a refused combination is recorded as unsupported — with the library's own reason — and shown in the support matrix instead of being benchmarked

Which libraries, and how

Thirteen libraries can produce a JSON schema. Two columns say how, both validated enums rather than free text:

Source — where the schema comes from:

Source Libraries
Converted at runtime arktype, effect, effect@beta, joi, sury, valibot, zod, zod/mini, zod/v3
Generated at build time typia
Already JSON Schema ajv, ata-validator, typebox

The last four aren't timed — reading a property or a build-time constant would measure the harness, not the library — so they report 0, and the source column says why.

Standard JSON Schema — how ~standard.jsonSchema is provided:

Support Libraries
Native zod, arktype
Native (opt in) sury, via S.enableStandardJSONSchema()
Separate package valibot, via @valibot/to-json-schema
None everything else

A library claiming any support has to hand over the schema exposing the interface, and a test asserts it converts exactly what the library's own API converts — so the column can't quietly drift from reality.

New dependencies: joi-to-json and zod-to-json-schema, alongside @valibot/to-json-schema.

Page

  • Support matrix above the results — one row per library, one column per target × direction, with the refusal message on hover
  • Filters for target (defaults to draft 2020-12) and type (input/output)
    • no optimizations filter — JIT/precompiled describes how a library validates, which says nothing about how it converts
  • Each result opens the JSON schema it generated, which differs a lot between libraries

@netlify

netlify Bot commented Jul 26, 2026

Copy link
Copy Markdown

Deploy Preview for schemabenchmarks ready!

Name Link
🔨 Latest commit a07507d
🔍 Latest deploy log https://app.netlify.com/projects/schemabenchmarks/deploys/6a6879d7f326be0007e236e5
😎 Deploy Preview https://deploy-preview-186--schemabenchmarks.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ab4e4becc7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bench/bench.json Outdated
Comment thread bench/src/scripts/bench/library.ts Outdated
Comment thread schemas/libraries/effect/benchmarks.ts Outdated
@DZakh
DZakh force-pushed the claude/standard-json-schema-case-u62fx5 branch from ab4e4be to fddebb6 Compare July 26, 2026 16:16
@EskiMojo14

EskiMojo14 commented Jul 26, 2026

Copy link
Copy Markdown
Member

my initial thoughts on this are that we should either call it Standard JSON Schema and only test schemas that actually implement the standard (no workarounds using custom adapters etc), or just test JSON Schema conversion without the requirement for the standard

the average user is not monkey patching their schemas to add Standard JSON Schema support, so we shouldn't either

this is the same reason we don't include TypeBox in our Standard Schema benchmarking - they provide an example of how you'd get it to work, but no official API

@DZakh

DZakh commented Jul 26, 2026

Copy link
Copy Markdown
Author

Yeah makes sense - I think general JSON Schema section with to/from API would be the best. And standard schema should be an additional column there. We can also add test suite compatability check TypeBox author suggests 👍

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 149bcf5630

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread website/e2e/nav.test.ts Outdated
Comment thread schemas/src/types.ts
@DZakh
DZakh marked this pull request as draft July 26, 2026 17:49
@DZakh
DZakh force-pushed the claude/standard-json-schema-case-u62fx5 branch 6 times, most recently from 0a35432 to b8154ab Compare July 27, 2026 15:14
@DZakh DZakh changed the title Add Standard JSON Schema benchmark case Add a JSON Schema benchmark case Jul 28, 2026
claude added 2 commits July 28, 2026 09:22
Benchmarks generating a JSON schema from a schema, through whichever API
each library provides for it, on a new /json-schema page.

The subject is a small schema with a codec, so the input and output types
differ and both are worth generating:

  z.object({
    id: z.number(),
    name: z.string(),
    price: z.codec(z.string(), z.number(), { decode: Number, encode: String }),
  })

Every target (draft 2020-12, draft 07, OpenAPI 3.0) and direction is
attempted. A library is expected to throw for anything it can't convert, so
those combinations are recorded as unsupported - with the library's own
reason - and shown in a support matrix instead of being benchmarked.

Thirteen libraries can produce a JSON schema, and two columns say how:

- source: where the schema comes from - converted at runtime, generated at
  build time (typia), or nothing to convert because the library's schemas are
  JSON Schema already (ajv, ata-validator, typebox). The last two are
  constants, so they're reported as 0 rather than timed - benchmarking a
  property read would measure the harness.
- standard JSON schema: whether the interface is implemented natively, behind
  an opt in, by a separate package, or not at all. A library claiming support
  has to provide the schema exposing `~standard.jsonSchema`, and it's asserted
  to convert exactly what the library's own API converts, so the column can't
  drift from reality.

What each library generates is checked two ways: the schema has to accept the
data of its own direction and reject the other's, and it has to match one of
the schemas in test/accepted-json-schemas.ts. Libraries disagree on how to
describe the same type, so rather than normalising, each accepted shape is
listed with the libraries that generate it - a new one fails the test until
it's looked at. `pnpm run gen:json-schemas` regenerates that list from what
the libraries currently produce, so the diff is what gets reviewed.

Adds joi-to-json and zod-to-json-schema, alongside @valibot/to-json-schema.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WLojRJg5z3PaekFfJSRvst
@DZakh
DZakh force-pushed the claude/standard-json-schema-case-u62fx5 branch from b8154ab to c2b7ea1 Compare July 28, 2026 09:22
@DZakh
DZakh marked this pull request as ready for review July 28, 2026 10:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a07507d6b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (direction === "output") {
throw new Error("No JSON schema can be generated for the output type");
}
return parse(jsonSchemaSubject, getJsonSchemaMode(target)) as object;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Benchmark Joi's native JSON Schema interface

With the Joi 18.2.3 build checked into this revision, this branch benchmarks the separate joi-to-json package and consequently records Standard JSON Schema support as none, rejects the native draft-2020-12 target, and omits output results. However, schemas/libraries/joi/download_compiled/unminified.js:539-542 exposes native schema["~standard"].jsonSchema.input and .output methods. Fresh evidence in this revision is the newly added parse(...) configuration here, so use Joi's native interface and a subject that exercises its input/output conversion instead; otherwise the support matrix and timings describe the adapter rather than Joi.

Useful? React with 👍 / 👎.

@DZakh

DZakh commented Jul 28, 2026

Copy link
Copy Markdown
Author

@EskiMojo14 I think this is good for now.

  • I'd maybe change the home page to show support level instead of performance
  • Include Spec Compliance Suite #183 json-schema-test suite coverage @sinclairzx81
    suggested
  • Add section for From JSON Schema

But these can be done separately. And I'm out of Claude this week 😰 https://x.com/dzakh_dev/status/2082024245417173175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants