Skip to content

[v4] json field: the migration guide's jsonSchema transform example fails typecheck and runs the json validator against fetch(undefined) #19401

Open

Description

@VeiaG

Describe the Bug

Payload 4 renamed the field-level typescriptSchema to jsonSchema. The json field already had a jsonSchema key with a different meaning: the schema its value is validated against. The two now collide, and the migration guide's example for the rename happens to be a json field:

{
  name: 'tags',
  type: 'json',
  jsonSchema: [() => ({ type: 'array', items: { type: 'string' } })],
}

Using that example verbatim on 4.0.0-beta.7:

  1. It fails typecheck. JSONField is { jsonSchema?: { fileMatch; schema; uri } } & Omit<FieldBase, 'admin' | 'jsonSchema' | 'validate'>, so the transform array is rejected:
    error TS2739: Type '(() => { type: string; items: { type: string; }; })[]' is missing the following properties from type '{ fileMatch: string[]; schema: JSONSchema4; uri: string; }': fileMatch, schema, uri
    
  2. Type generation does work. configToJSONSchema applies jsonSchema transforms whenever Array.isArray(field.jsonSchema), without looking at the field type. The generated type is tags?: string[].
  3. Every save runs the json validator against the array. The validator calls validateJSONSchema whenever jsonSchema is truthy, and treats it as { uri, schema }. With an array, uri and schema are undefined, so fetch(undefined) is called and never awaited:
    • an unhandled rejection, TypeError: Failed to parse URL from undefined, on every create/update;
    • the value is accepted (the validator returns true);
    • the field config is mutated: the transform array gets a .schema property holding the Promise.

So on v4 a json field can either validate against a schema or transform its generated type, and the documented way to do the latter breaks at runtime. On 3.x, JSONField was Omit<FieldBase, 'admin' | 'validate'>, so it kept typescriptSchema next to its own jsonSchema, and both worked.

Expected: the migration guide's example works on a json field, or the guide uses a field type where it does. A json field can set both a validation schema and type transforms, as on v3.


Also, related, current beta docs for json field has 2 jsonSchema fields in a table:

Image

https://payloadcms.com/docs/beta/fields/json

Link to the code that reproduces this issue

https://github.com/VeiaG/payload-4-reproductions/tree/repro-json-field-jsonschema-transforms

  • apps/next/collections/JsonTransforms.ts: the guide's example verbatim. @ts-expect-error marks the TS2739.
  • apps/next/helpers/seed.ts: creates a document on boot.

Code:

Reproduction Steps

  1. pnpm install && pnpm dev
  2. On boot the seed saves { tags: ['a', 'b'] } and the log shows:
    unhandledRejection: Failed to parse URL from undefined
    [repro] json-transforms: saved 6aeccdf2b88da615a116ac52
    
  3. payload-types.ts has tags?: string[], so the transforms did run.
  4. Remove the @ts-expect-error in JsonTransforms.ts and run tsc to get TS2739.

Which area(s) are affected?

area: core

Environment Info

payload: 4.0.0-beta.7
Node: 24
OS: Windows 11

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Nov 6, 2026
  2. added
    area: core
    and removed
    validate-reproduction
    on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPayload OSSarea: corecreated-by: Contributorstatus: needs-triagev3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions