{"id":14822,"library":"prisma-json-types-generator","title":"Prisma JSON Types Generator","description":"The `prisma-json-types-generator` is a development-time tool that enhances the Prisma client by providing strict TypeScript typings for `Json` and `String` fields, replacing Prisma's default `JsonValue` with custom, user-defined interfaces. The current stable version is `4.1.1`, which primarily supports Prisma 7 and above, with earlier `v3.x` releases supporting Prisma 6. This package operates during the `prisma generate` step, ensuring all type transformations occur at compile-time without introducing any runtime overhead. Its release cadence generally follows major Prisma version updates, with patch releases for bug fixes and minor improvements. Key differentiators include robust type-safety for complex JSON structures, the ability to define string literal enums without relying on native database enums, flexible type configuration through global namespaces or inline annotations, and compatibility with multiple Prisma clients in a single project. It works seamlessly across all database drivers supported by Prisma.","status":"active","version":"4.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/arthurfiorette/prisma-json-types-generator","tags":["javascript","prisma","types","prisma2","generator","json","typesafe","typescript"],"install":[{"cmd":"npm install prisma-json-types-generator","lang":"bash","label":"npm"},{"cmd":"yarn add prisma-json-types-generator","lang":"bash","label":"yarn"},{"cmd":"pnpm add prisma-json-types-generator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for the generated Prisma client to be type-enhanced.","package":"@prisma/client","optional":false},{"reason":"The core Prisma CLI tool that runs this generator during the code generation phase.","package":"prisma","optional":false},{"reason":"The generator produces TypeScript definitions, so TypeScript is a peer dependency for compilation.","package":"typescript","optional":false}],"imports":[],"quickstart":{"code":"/* schema.prisma */\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\ngenerator json {\n  provider  = \"prisma-json-types-generator\"\n  namespace = \"PrismaJson\" // Optional: define a custom namespace for generated types\n  allowAny  = false\n}\n\nmodel User {\n  id        String @id @default(uuid())\n  settings  Json   @db.Text @PrismaJson.UserSettings // Apply custom type\n}\n\n/// @PrismaJson.UserSettings\ntype UserSettings = {\n  theme: \"dark\" | \"light\";\n  notifications: boolean;\n  preferences?: { locale: string; timezone: string; };\n}\n\n/* index.ts */\nimport { PrismaClient } from '@prisma/client';\nimport { UserSettings } from './@prisma/client'; // Import generated type (adjust path as needed if namespace is used)\n\nconst prisma = new PrismaClient();\n\nasync function main() {\n  // Example: Create a user with strongly typed JSON settings\n  const user = await prisma.user.create({\n    data: {\n      settings: {\n        theme: 'dark',\n        notifications: true,\n        preferences: { locale: 'en-US', timezone: 'UTC' }\n      },\n    },\n  });\n\n  console.log('Created user:', user);\n  // Accessing settings provides full TypeScript autocompletion and type-checking\n  console.log('User theme:', user.settings.theme); // 'dark'\n\n  // Example: Update user settings with type-safety\n  const updatedUser = await prisma.user.update({\n    where: { id: user.id },\n    data: {\n      settings: {\n        theme: 'light', // Autocompletion for 'dark' | 'light'\n        notifications: false,\n        preferences: { locale: 'es-ES', timezone: 'America/Mexico_City' }\n      },\n    },\n  });\n\n  console.log('Updated user:', updatedUser);\n  // If you try to assign an invalid type, TypeScript will catch it at compile time.\n  // e.g., updatedUser.settings.theme = 'invalid'; // Type error\n\n}\n\nmain().catch(console.error).finally(() => prisma.$disconnect());","lang":"typescript","description":"This quickstart demonstrates how to configure the `prisma-json-types-generator` in `schema.prisma` to apply custom TypeScript types to a `Json` field. It then shows how to interact with the Prisma client, benefiting from compile-time type-safety and autocompletion for the `settings` field."},"warnings":[{"fix":"For Prisma 7+, use `prisma-json-types-generator@^4`. For Prisma 6 and below, use `prisma-json-types-generator@^3`.","message":"Upgrading to `prisma-json-types-generator` v4.x requires Prisma version 7 or newer. Older Prisma versions (v6 and below) are only supported by `prisma-json-types-generator` v3.x and earlier. Mixing incompatible versions will lead to type generation errors.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Review GitHub issue #542 for details on the v3.x maintenance status. Consider upgrading to v4.x and Prisma 7 for active development and support.","message":"Versions `3.6.2` and below had a significant \"Maintenance Status Update\" indicating a change in the project's maintenance approach (see GitHub issue #542 for details). While v4.x is actively maintained, users on v3.x should be aware of this historical context regarding project stability.","severity":"gotcha","affected_versions":"<=3.6.2"},{"fix":"Upgrade to `prisma-json-types-generator@4.0.1` or later to ensure correct type generation for update inputs with Prisma 7.","message":"Early v4.x versions (e.g., `4.0.0-beta.1` to `4.0.0`) could produce incorrect types for `UpdateInput` and `NullableJsonNullValueInput` due to missing `Prisma.` namespace prefixes when used with Prisma 7. These issues were resolved in `v4.0.0-beta.2` and `v4.0.1`.","severity":"gotcha","affected_versions":">=4.0.0-beta.1 <4.0.1"},{"fix":"Ensure you are on `prisma-json-types-generator@4.0.0` or higher for correct typing in `groupBy` scenarios involving JSON fields and lowercase model names.","message":"Previous versions might have incorrectly typed JSON fields for models with lowercase names in `groupBy` operations. This was addressed in `v4.0.0`.","severity":"gotcha","affected_versions":"<4.0.0"},{"fix":"Upgrade to `prisma-json-types-generator@4.1.1` or later to fix type generation for nullable `Int` or `Float` fields in `where` clauses without explicit annotations.","message":"Types generated on `where` inputs for nullable integer/float fields without explicit type annotations were incorrect in versions prior to `v4.1.1`.","severity":"gotcha","affected_versions":"<4.1.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `prisma generate` has been run after configuring the generator in `schema.prisma`. Verify `prisma-json-types-generator` is correctly listed as a generator provider and that its version is compatible with your installed `prisma` and `@prisma/client` versions (v4+ for Prisma 7+, v3 for Prisma 6).","cause":"The `prisma-json-types-generator` has not run, is incorrectly configured, or an incompatible version of Prisma/generator is in use, preventing the custom JSON types from being applied.","error":"Property 'someJsonField' does not exist on type 'Prisma.JsonValue'."},{"fix":"Update `prisma-json-types-generator` to version `4.0.1` or later, which contains fixes for correctly applying the `Prisma.` namespace prefix in generated types.","cause":"This error often indicates issues with Prisma 7's required `Prisma.` namespace prefix for certain input types that the generator modifies, specifically for `NullableJsonNullValueInput` or `UpdateInput` types.","error":"Type 'string' is not assignable to type 'Prisma.NullableJsonNullValueInput<string> | MyCustomType'."}],"ecosystem":"npm"}