Skip to content

fix(utils): support array and dynamic types for .json fields in DML - #16236

Merged
kodiakhq[bot] merged 1 commit into
developfrom
fix/json-array
Aug 6, 2026
Merged

fix(utils): support array and dynamic types for .json fields in DML#16236
kodiakhq[bot] merged 1 commit into
developfrom
fix/json-array

Conversation

@shahednasser

Copy link
Copy Markdown
Member

The .json field maps to a jsonb column, which can hold any JSON serializable value, such as arrays.

With the current approach, we always typed json fields as Record<string, unknown>. So, if you were to set an array value it would show a type error, even though it is supported by the backend / database.

This PR allows passing a type argument to .json() to specify the expected type of the field, which maps into types in the module's service and the data model itself.

For example:

const Post = model.define("post", {
  id: model.id().primaryKey(),
  title: model.text().translatable(),
  extra: model.json<{ code: string }[]>()
})

// in a route or workflow
const post = await blogModuleService.createPosts({
    title: "My First Post",
    extra: [
      {
        code: "code1",
      },
      {
        code: "code2",
      }
    ]
  })

  const codes = post.extra.map((item) => item.code)

Base json fields retain their Record<string, unknown> type.

Closes DX-2824

@shahednasser
shahednasser requested a review from a team as a code owner July 29, 2026 14:56
@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c169221

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 79 packages
Name Type
@medusajs/utils Patch
@medusajs/event-bus-redis Patch
@medusajs/framework Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/query Patch
@medusajs/workflows-sdk Patch
@medusajs/cli Patch
@medusajs/medusa-oas-cli Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/event-bus-local Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/draft-order Patch
@medusajs/loyalty-plugin Patch
@medusajs/core-flows Patch
integration-tests-http Patch
@medusajs/oas-github-ci Patch
@medusajs/js-sdk Patch
@medusajs/types Patch
@medusajs/http-types-generator Patch
@medusajs/deps Patch
@medusajs/eslint-plugin Patch
@medusajs/telemetry Patch
@medusajs/admin-bundler Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/dashboard Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@medusa-os-bot

medusa-os-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

Thanks for the contribution! Initial automated review looks good.

Team member PR adding a type parameter to JSONProperty and the json() builder method so callers can specify array or other JSON-serializable types. The change is purely type-level with no runtime impact. Tests use expectTypeOf to verify the default resolves to Record<string, unknown> and that custom types (e.g. arrays) thread through correctly. NoInfer<T> is used correctly to prevent contextual widening. Changeset included at patch level. No security, performance, or correctness concerns.

Triggered by: manual workflow dispatch

@NicolasGorga NicolasGorga left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@kodiakhq
kodiakhq Bot merged commit 1fb31df into develop Aug 6, 2026
92 of 105 checks passed
@kodiakhq
kodiakhq Bot deleted the fix/json-array branch August 6, 2026 06:01
@github-actions github-actions Bot mentioned this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants