Standard JSON Schema#134
Conversation
fabian-hiller
left a comment
There was a problem hiding this comment.
Just some details. Rest should be ready. 🔥
61ef405 to
5a27872
Compare
fabian-hiller
left a comment
There was a problem hiding this comment.
A few smaller notes. Otherwise, I am happy.
e1e0dd9 to
07779d2
Compare
|
This looks great! However, since JSON Schema itself can’t represent const schema = z.union(z.string(), z.undefined());
schema['~standard'].jsonSchema.output();
// current behavior:
// { anyOf: [ { type: 'string' }, { not: {} } ] }
// expected:
// [false, { type: 'string' }]This is especially useful when generating OpenAPI specs, since OpenAPI has explicit fields to indicate whether body/query/header/param values are required.
|
|
I'm not sure how much of the RFC will be carried over to the README but a few thoughts on the body of the PR:
Are we still planning to use this terminology as opposed to something less prescriptive like "JSON Schema Source"?
I would word this differently e.g. "vendor-specific parameters accepted by the implementer's builtin JSON Schema conversion API"
Maybe something like: Staring with the next Standard JSON Schema is orthogonal to Standard Schema. This interface contains no affordance for data validation. Think of them as "traits" or "interfaces". Any given object/instance/entity can implement one or both. |
|
@unnoq I see two relevant scenarios here:
Because of Let me know if I'm missing something about how you'd expect this to be used, but as it stands I'd want to avoid baking this can of worms into the spec. |
ssalbdivad
left a comment
There was a problem hiding this comment.
A couple very minor notes. Look great, excited to ship this 😄
Effect Schema works the same way, +1 to
|
|
Any ETA on this? We would love to use this in TanStack AI! |
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | [`4.1.13` -> `4.2.0`](https://renovatebot.com/diffs/npm/zod/4.1.13/4.2.0) |  |  | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/clentfort/adameter). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi40Mi4yIiwidXBkYXRlZEluVmVyIjoiNDIuNDIuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Adoption](https://docs.renovatebot.com/merge-confidence/) | [Passing](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | [`4.1.13` -> `4.2.0`](https://renovatebot.com/diffs/npm/zod/4.1.13/4.2.0) |  |  |  |  | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/inabagumi/shinju-date). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi40Mi4yIiwidXBkYXRlZEluVmVyIjoiNDIuNDIuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiYm90OiByZW5vdmF0ZSJdfQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | [`4.1.13` -> `4.2.0`](https://renovatebot.com/diffs/npm/zod/4.1.13/4.2.0) |  |  | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/mgurov/lokito). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi40Mi4yIiwidXBkYXRlZEluVmVyIjoiNDIuNDIuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
|
cc @pullfrog review this |
There was a problem hiding this comment.
Comprehensive review complete. Found one critical issue in the examples that will prevent type-checking from passing. The spec implementation looks solid and well-designed.
| */ | ||
| import { toJsonSchema } from "@valibot/to-json-schema"; // adds JSON Schema conversion methods | ||
|
|
||
| acceptStandardJSONSchema(toJsonSchema(v.string())); |
There was a problem hiding this comment.
v is not defined or imported. This should be import * as v from "valibot" at the top, or the example should use a qualified reference like v.string().
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | [`4.1.13` -> `4.2.0`](https://renovatebot.com/diffs/npm/zod/4.1.13/4.2.0) |  |  | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/RobinTail/express-zod-api). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi40Mi4yIiwidXBkYXRlZEluVmVyIjoiNDIuNDIuMiIsInRhcmdldEJyYW5jaCI6Im1hc3RlciIsImxhYmVscyI6W119--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Anna Bocharova <[email protected]>
|
This has landed in Announcement post: https://x.com/colinhacks/status/2000704277606752450 |
This PR contains the following updates: | Package | Type | Update | Change | OpenSSF | |---|---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | dependencies | minor | [`4.1.13` -> `4.2.0`](https://renovatebot.com/diffs/npm/zod/4.1.13/4.2.0) | [](https://securityscorecards.dev/viewer/?uri=github.com/colinhacks/zod) | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At 12:00 AM through 04:59 AM and 10:00 PM through 11:59 PM, Monday through Friday ( * 0-4,22-23 * * 1-5 ), Only on Sunday and Saturday ( * * * * 0,6 ) (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/settlemint/docs). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41NC4yIiwidXBkYXRlZEluVmVyIjoiNDIuNTQuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Updated zod to 4.2.0 to add Standard JSON Schema support and new helpers: z.fromJSONSchema, z.xor, and z.looseRecord. Minor version bump; no code changes needed. <sup>Written for commit 50e8093. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
## Background Standard JSON Schema was released as part of Standard Schema 1.1.0 (see standard-schema/standard-schema#134 ). This enables integration of any schema library that supports Standard JSON Schema. Additionally, the current peer dependency mechanism has issues in certain environments (see #10122 ). ## Summary * remove direct Effect, Arktype, and Valibot integrations * support Standard JSON Schema ## Manual Verification - [x] test zod direct `examples/ai-core/src/generate-text/anthropic-output-object-zod.ts` - [x] test zod v4 `examples/ai-core/src/generate-text/anthropic-output-object-zod4.ts` - [x] test arktype `examples/ai-core/src/generate-text/anthropic-output-object-arktype.ts` - [x] test valibot `examples/ai-core/src/generate-text/anthropic-output-object-valibot.ts` ## Future Work * improve schema library support documentation ## Related Issues Fixes #10122 Resolves #11044 --------- Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Type | Update | Change | OpenSSF | |---|---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | dependencies | minor | [`4.1.13` -> `4.2.1`](https://renovatebot.com/diffs/npm/zod/4.1.13/4.2.1) | [](https://securityscorecards.dev/viewer/?uri=github.com/colinhacks/zod) | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.1`](https://redirect.github.com/colinhacks/zod/compare/v4.2.0...5b5b129315fbc94a3b0d6244185eaeefcbe438d1) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.2.0...v4.2.1) ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At 12:00 AM through 04:59 AM and 10:00 PM through 11:59 PM, Monday through Friday ( * 0-4,22-23 * * 1-5 ), Only on Sunday and Saturday ( * * * * 0,6 ) (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/settlemint/network-bootstrapper). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41NC4yIiwidXBkYXRlZEluVmVyIjoiNDIuNTQuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | [`4.1.12` -> `4.2.0`](https://renovatebot.com/diffs/npm/zod/4.1.12/4.2.0) |  |  | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) ### [`v4.1.13`](https://redirect.github.com/colinhacks/zod/compare/v4.1.12...4063e802d539d04182fc3e66a543ae6d1ba5658e) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.12...v4.1.13) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/JoshuaKGoldberg/flint). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41OS4wIiwidXBkYXRlZEluVmVyIjoiNDIuNTkuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | [`4.1.13` -> `4.2.0`](https://renovatebot.com/diffs/npm/zod/4.1.13/4.2.0) |  |  | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/infonl/dimpact-zaakafhandelcomponent). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41OS4wIiwidXBkYXRlZEluVmVyIjoiNDIuNTkuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | [`^4.1.13` -> `^4.2.0`](https://renovatebot.com/diffs/npm/zod/4.1.13/4.2.0) |  |  | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - "after 8:00 before 23:00 every weekday except on Friday" in timezone UTC. 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/divvi-xyz/divvi-mcp-server). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41OS4wIiwidXBkYXRlZEluVmVyIjoiNDIuNTkuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsibnBtIiwicmVub3ZhdGUiXX0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | [`4.1.13` -> `4.2.1`](https://renovatebot.com/diffs/npm/zod/4.1.13/4.2.1) |  |  | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.2.1`](https://redirect.github.com/colinhacks/zod/compare/v4.2.0...5b5b129315fbc94a3b0d6244185eaeefcbe438d1) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.2.0...v4.2.1) ### [`v4.2.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.2.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.1.13...v4.2.0) #### Features ##### Implement Standard JSON Schema [standard-schema/standard-schema#134](https://redirect.github.com/standard-schema/standard-schema/pull/134) ##### Implement `z.fromJSONSchema()` ```typescript const jsonSchema = { type: "object", properties: { name: { type: "string" }, age: { type: "number" } }, required: ["name"] }; const schema = z.fromJSONSchema(jsonSchema); ``` ##### Implement `z.xor()` ```typescript const schema = z.xor( z.object({ type: "user", name: z.string() }), z.object({ type: "admin", role: z.string() }) ); // Exactly one of the schemas must match ``` ##### Implement `z.looseRecord()` ```typescript const schema = z.looseRecord(z.string(), z.number()); // Allows additional properties beyond those defined ``` #### Commits: - [`af49c08`](https://redirect.github.com/colinhacks/zod/commit/af49c084f66339110d00e37ff71dc7b3b9f2b7ef) Update docs for JSON Schema conversion of `z.undefined()` ([#​5504](https://redirect.github.com/colinhacks/zod/issues/5504)) - [`767f320`](https://redirect.github.com/colinhacks/zod/commit/767f320318986e422f524b939f1a7174544fda2e) Add `.toJSONSchema()` method ([#​5477](https://redirect.github.com/colinhacks/zod/issues/5477)) - [`e17dcb6`](https://redirect.github.com/colinhacks/zod/commit/e17dcb63573397063e87d7c7fe10a5a78968181a) Add `z.fromJSONSchema()`, `z.looseRecord()`, `z.xor()` ([#​5534](https://redirect.github.com/colinhacks/zod/issues/5534)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/ykzts/ykzts). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41OS4wIiwidXBkYXRlZEluVmVyIjoiNDIuNTkuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

RFC:
StandardJSONSchemaThis RFC proposes the addition of a new spec:
StandardJSONSchema. This spec can be implemented by any entity that both:This spec provides a standardized, unified JSON Schema representation that preserves inferred type information.
Motivation
Many libraries need JSON Schema representations of type information:
Previously, type information was commonly destroyed in the process of converting a schema (Zod, ArkType, Valibot) to JSON Schema. This spec provides a standardized, unified JSON Schema representation that preserves inferred type information.
The spec
This new proposal aims to solve that with the addition of a new spec:
StandardJSONSchemaV1.This provides a standardized interface that can be implemented by any JavaScript object/instance/entity that can be converted into a JSON Schema representation. We expect most implementers to be schema libraries, but other libraries (ORMs, form builders, etc.) can also implement it.
FAQ
What's the relationship between this and Standard Schema?
Staring with the next
@standard-schema/specversion, Standard JSON Schema will be published alongside the existing Standard Schema spec.Standard JSON Schema is orthogonal to Standard Schema. This interface contains no affordance for data validation. Think of them as "traits" or "interfaces". Any given object/instance/entity can implement one or both.
What schema libraries support this spec?
The answer to this question is a little more nuanced than with regular Standard Schema. The spec can be implemented by any object that represents or can be converted to JSON Schema. It's intentionally designed to support multiple use cases.
If a library directly encapsulates JSON Schema conversion logic within schemas themselves (say, as a method), it can directly implement the spec. If not, the library may provide a
toJSONSchemafunction that returns a value that implements this spec.Why multiple
targetvalues?Different tooling requires different versions of JSON Schema. Currently there is a divide in the ecosystem between
"draft-07"and"draft-2020-12". Library authors that implement this spec are encouraged to implement as many formats as is practical, which a special emphasis on"draft-07"and"draft-2020-12". Supporting multiple formats is not required to implement the spec; it is entirely on a best-effort basis.Does the spec account for future versions of JSON Schema?
Yes, the type signature for
"target"was intentionally widened with{} & string. This allows libraries to support unspecified formats. It also allows the spec to evolve to include future versions of JSON Schema without breaking assignability down the line.What's
"openapi-3.0"?The OpenAPI 3.0 specification (still in wide use) implements its own schema definition format. It's a superset of JSON Schema
"draft-04"that's augmented with additional keywords likenullable. Despite not being an official JSON Schema draft, it's in wide use and has been included in the list of recommended drafts.Why both
jsonSchema.inputandjsonSchema.output?Many schemas perform transformations during validation. For example, a schema might accept a string as input (
"123") but output a number (123). The input and output types can differ, so their JSON Schema representations need to differ as well. ThejsonSchema.inputmethod generates a JSON Schema for the input type, whilejsonSchema.outputgenerates one for the output type. In cases where input and output types are identical, both methods will return the same schema.What about error handling?
If a given schema/entity cannot be converted to JSON Schema, the conversion method call may throw. They may also throw if the entity is non-convertible or otherwise cannot be soundly reprsented as JSON Schema. Any integrating frameworks/libraries should account for this.
Why is this a separate spec instead of adding to
StandardSchemaV1?The two concerns are orthogonal.
StandardSchemaV1is about validation, whileStandardJSONSchemaV1is about introspectability and JSON Schema generation. Keeping them separate allows greater flexibility.I'm a schema library author. How do I implement this spec?
Refer to the implementation example for a worked example.
I want to accept JSON Schema from a user. How do I do that?
Refer to the integration example for a worked example.
What if I want to accept only schemas that implement both
StandardSchemaandStandardJSONSchema?The two specs are implemented as plain TypeScript interfaces, so you can merge them (and any future specs) as needed for your use case.