JSON to Prisma Schema Model Generator — Free Online
Convert JSON to a Prisma schema model with correct field types, @id, @default, and @map directives using AI. For PostgreSQL, MySQL, and SQLite. Free, no sign-up.
JSON to Prisma Schema Model Generator — Free Online
About JSON to Prisma Schema Model Generator — Free Online
JSON to Prisma Schema converts a JSON object or sample data payload into a Prisma schema model, inferring field types and adding appropriate decorators like @id, @default, and @updatedAt. Developers use it to scaffold database models quickly from existing API responses or data fixtures, eliminating manual type mapping when adopting Prisma in a new or existing project.
JSON to Prisma Type Mapping
| JSON Type | Example Value | Prisma Field Type | Notes |
|---|---|---|---|
| string | "hello" | String | Default mapping for all string values |
| string (ISO date) | "2024-01-15T10:00:00Z" | DateTime | Detected by ISO 8601 format heuristic |
| number (integer) | 42 | Int | Whole numbers map to Int |
| number (float) | 3.14 | Float | Numbers with decimals map to Float |
| boolean | true / false | Boolean | Direct 1-to-1 mapping |
| null | null | String? | Null values produce optional (?) fields |
| object | {...} | Json | Nested objects default to Json type |
| array of objects | [{...}] | Json | Heterogeneous arrays use Json |
| array of strings | ["a","b"] | String[] | Homogeneous primitive arrays use array type |
| id / _id field | "abc123" or 1 | String @id or Int @id | @id decorator added automatically |
Prisma Schema vs Alternatives
| Feature | Prisma Schema | TypeORM Entity | Mongoose Schema | Sequelize Model |
|---|---|---|---|---|
| Language | Prisma SDL (.prisma) | TypeScript decorators | JavaScript/TypeScript | JavaScript/TypeScript |
| Type safety | Full (generated client) | Full (via decorators) | Partial (via TS plugin) | Partial |
| Auto-migration | prisma migrate dev | Manual or synchronize:true | No built-in migrations | sequelize-cli migrate |
| Relations syntax | @relation directive | @ManyToOne etc. | ref: 'Model' | belongsTo / hasMany |
| JSON field support | Json native type | @Column({type:'jsonb'}) | Mixed / Schema.Types.Mixed | DataTypes.JSON |
| Enum support | enum keyword | @Column enum option | String with validate | DataTypes.ENUM |
| Generated types | PrismaClient types | Entity class | Document interface | Model class |
| DB support | PostgreSQL, MySQL, SQLite, MongoDB, CockroachDB | Many relational DBs | MongoDB only | Many relational DBs |
Frequently Asked Questions
How does JSON to Prisma schema handle nested objects?
Nested JSON objects are mapped to the Json Prisma field type by default, since Prisma does not inline nested models automatically. If you want a proper relational model, you should manually split the nested object into a separate model and add a @relation field. Prisma supports Json natively on PostgreSQL, MySQL, and MongoDB.
What Prisma field type should I use for a UUID primary key from JSON?
If your JSON id field contains a UUID string, the correct Prisma type is String with @id and @default(uuid()) decorators: id String @id @default(uuid()). The tool detects fields named id or _id and adds @id automatically. You can manually add @default(uuid()) or @default(cuid()) depending on your ID generation strategy.
Can I convert a JSON array to a Prisma schema?
Yes — the tool accepts a JSON array and uses the first object (or merges all objects) to infer the full field set, so optional fields present in only some records are detected. The resulting model represents the shape of one array element. Arrays of primitive values within a record (e.g., String[]) are rendered as Prisma list types where the database supports them.
How do I add @updatedAt and @createdAt to a Prisma model from JSON?
Fields named updatedAt or updated_at with a DateTime type automatically receive the @updatedAt decorator in Prisma, which tells the database to update the timestamp on every write. For createdAt, use @default(now()) so Prisma sets the value on record creation. You can add these manually after generation: createdAt DateTime @default(now()) and updatedAt DateTime @updatedAt.
Does Prisma support optional fields and how are they generated from JSON?
Prisma marks a field as optional by appending ? to the type, for example String?. The JSON to Prisma converter produces optional fields when a JSON value is null or when a key is missing in some records of an array input. Required fields have no ?, and Prisma will throw a runtime error if you insert a record without providing a value for them.
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.