JSON to Prisma Schema Model Generator
Convert JSON to Prisma schema models online. Infers Int, String, Boolean and DateTime columns, marks @id primary keys and optional fields. Free, no upload.
To turn JSON into a Prisma model, paste a representative record on the left. Each property is mapped to a Prisma scalar type such as Int, String, Boolean or DateTime, an id field becomes @id @default, and the right pane returns a block you can paste into schema.prisma.
Prisma schema will appear here…
📊 Real-Time Structural Payload Evaluation
Programmatic Execution Modules
Native runtime recipes for automated pipelines • Zero external cloud dependencies
npx prisma db pull && npx prisma format// Dynamic PSL Generator with scalar mapping
export function inferPrismaField(key: string, val: unknown): string {
if (val === null) return `${key} String?`;
if (typeof val === 'number') {
return Number.isInteger(val) ? `${key} Int` : `${key} Float`;
}
if (typeof val === 'boolean') return `${key} Boolean`;
if (Array.isArray(val)) return `${key} String[]`;
if (typeof val === 'object') return `${key} Json`;
return `${key} String`;
}IEEE 754 Float Coercion vs 64-Bit Integer Precision
Numeric Coercion HeuristicsJavaScript numbers are double-precision floats (64-bit). Ingesting timestamps or database IDs exceeding 2^53 - 1 causes precision truncation. The parser maps standard integers to Int, large integers to BigInt, and fractional numbers to Float/Decimal.
Composite Sub-Documents vs Relational Foreign Keys
Relational Topology HeuristicsNested JSON objects can be mapped either as PostgreSQL Jsonb scalar columns or as distinct relational models linked via foreign keys (@relation). The parser synthesizes standalone child models when primary key patterns are detected.
📚 Task-Specific Reference Guides & Specifications
1 Technical GuidesFrequently Asked Questions: JSON to Prisma
How does the schema generator distinguish PostgreSQL relational models from MongoDB document models in schema.prisma?
The generator differentiates provider-specific schema requirements at the AST level. For relational targets (PostgreSQL, MySQL, SQLite), primary keys map to relational ID conventions such as `id Int @id @default(autoincrement())` or `id String @id @default(uuid())`, and nested entities trigger foreign key relations (`@relation(...)`). Conversely, for MongoDB datasource providers, primary keys require strict ObjectId mapping syntax: `id String @id @default(auto()) @map("_id") @db.ObjectId`. Additionally, nested JSON structures in MongoDB can be mapped to Prisma composite types (`type SubDocument { ... }`) rather than standalone relational models.
How are Prisma attribute directives (@id, @default, @updatedAt, @unique) inferred from JSON keys?
The engine applies heuristic attribute pattern matching: properties matching `id`, `_id`, or `uuid` are assigned the `@id` directive with an appropriate generator (`@default(autoincrement())` for integers or `@default(uuid())` for strings). Fields representing creation dates (`createdAt`) receive `@default(now())`, while modification timestamps (`updatedAt`) receive `@updatedAt`. Distinct identifier fields (such as `email`, `slug`, or `username`) receive the `@unique` constraint to enforce schema-level uniqueness.
How does scalar type inference classify numbers into Prisma Int, BigInt, Float, and Decimal types?
JSON specifies a single numeric representation (IEEE 754 float). The generator inspects values across all sample rows: integers within the signed 32-bit range (`-2,147,483,648` to `2,147,483,647`) map to Prisma `Int`. Numbers exceeding 32-bit thresholds map to `BigInt`. Non-integer fractional values map to `Float` by default, or to `Decimal` (with `@db.Decimal(10, 2)`) when property names denote currency or financial transactions (`price`, `amount`, `balance`, `subtotal`), preventing floating-point rounding inaccuracies.
How are nested JSON objects and arrays resolved between relational models and composite embedded types?
When an input payload contains nested objects (e.g. `{ user: { address: { street: "..." } } }`), the generator can resolve the relationship in two ways. In relational mode (PostgreSQL), it synthesizes a secondary `Address` model and establishes a 1-to-1 or 1-to-many `@relation(fields: [addressId], references: [id])` foreign key binding. In denormalized or document mode (MongoDB/PostgreSQL JSON columns), it emits the field as a native `Json` scalar type or a composite type (`type Address`), avoiding unnecessary table joins.
How are null values and absent properties translated into Prisma optional modifiers (?) and default fallbacks?
In Prisma schema syntax, fields marked with `?` denote database nullable columns (`NULL`), whereas unmarked fields are strictly `NOT NULL`. If an input payload contains explicit `null` values or if a key is absent in some records across a multi-object JSON array, the generator marks the field as optional (e.g. `bio String?`, `deletedAt DateTime?`). For boolean flags and counters with absent values, it can infer default fallbacks (e.g. `Boolean @default(false)` or `Int @default(0)`), ensuring valid migrations without schema validation rejections.
🔍 Developer Query Intent Index
How to use the JSON to Prisma
Step-by-step workflow — executed 100% locally in your browser memory.
- 1
Paste a representative record
Put one object — or an array of them — into the left-hand input pane. An array lets the generator work out which fields are optional.
- 2
Name the model
Set the model name in PascalCase singular, which is the Prisma convention: `User`, not `users`.
- 3
Read the generated model
The right-hand pane shows a model block with typed fields, an @id on the primary key, and @default(now()) on timestamp-looking fields.
- 4
Add relations, then migrate
Wire up relation fields by hand, then run `prisma migrate dev` against a development database.
⚡ Technical Specifications & Engineering Compliance Matrix
| Specification Standard | Prisma Schema Language (PSL) v5.x / DDL Abstract Syntax Tree |
|---|---|
| Architecture: | ast-compiler |
| Time Complexity | O(N) single-pass type inference with relationship synthesis |
| Memory Footprint | O(M + F) where M = models, F = total AST fields |
| Data Privacy & Egress | Zero remote transmission (100% in-browser memory) |
| Last reviewed | by the JSON2X Core Team. |
Related Developer Tools
Architecture: ast-compiler •Spec: Prisma Schema Language (PSL) v5.x / DDL Abstract Syntax Tree •Last reviewed by the JSON2X Core Team.