← All guides

JSON to Prisma

Quick Answer

Use the JSON Schema Generator with the Prisma tab to convert JSON into Prisma model definitions. Paste your JSON to generate a starting point for your database schema. Note: not every JSON structure maps cleanly to a relational model — always review and refine the output.

What is Prisma?

Prisma is a next-generation ORM for Node.js and TypeScript. It provides type-safe database access with auto-generated queries, migrations, and a visual data browser. Prisma models define your database tables and relationships.

When to Use This Tool

  • Bootstrapping a new project with existing JSON data
  • Converting NoSQL documents to relational models
  • Creating initial schema drafts from API responses
  • Learning Prisma syntax from familiar JSON structures

Step-by-Step Instructions

  1. Open the tool: Navigate to the JSON Schema Generator.
  2. Select Prisma tab: Click on the "Prisma" tab.
  3. Paste your JSON: Copy your JSON sample and paste it into the input area.
  4. Review the model: The tool generates a Prisma model based on your JSON structure.
  5. Copy and refine: Copy the generated model to your schema.prisma file.
  6. Adjust as needed: Add relationships, constraints, and refine field types.

Example

Input JSON:

{
  "id": 1,
  "title": "My Post",
  "content": "Post content here...",
  "published": true,
  "authorId": 5,
  "tags": ["tech", "tutorial"],
  "createdAt": "2024-01-15T10:00:00Z"
}

Generated Prisma Model:

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  content   String
  published Boolean  @default(false)
  authorId  Int
  tags      String[]
  createdAt DateTime @default(now())
}

Type Mappings

JSON TypePrisma Type
StringString
Number (integer)Int
Number (float)Float or Decimal
BooleanBoolean
ArrayType[] (scalar list)
ObjectSeparate model + relation
Date stringDateTime

Important Considerations

Relationships

The tool generates flat models. You'll need to manually add relationships:

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  content   String
  published Boolean  @default(false)
  authorId  Int
  author    User     @relation(fields: [authorId], references: [id])
  tags      String[]
  createdAt DateTime @default(now())
}

model User {
  id    Int    @id @default(autoincrement())
  posts Post[]
}

IDs and Defaults

The tool attempts to identify ID fields. Review and adjust:

id Int @id @default(autoincrement())  // Auto-increment integer
// OR
id String @id @default(uuid())         // UUID
// OR
id String @id @default(cuid())         // CUID

Constraints

Add constraints for data integrity:

email String @unique
name  String @db.VarChar(255)

Best Practices

  • Review generated models: The tool provides a starting point, not a final schema
  • Normalize data: Break nested objects into separate models with relations
  • Use appropriate IDs: Choose between auto-increment, UUID, or CUID based on your needs
  • Add indexes: Add @index for frequently queried fields
  • Run migrations: Use npx prisma migrate dev after updating your schema

Related Tools

FAQ

Q: Can I generate the entire schema file?
A: The tool generates model definitions only. You'll need to add the datasource and generator blocks manually.

Q: How do I handle nested objects?
A: The tool flattens nested objects. For proper relational design, extract nested objects into separate models and create relations.

Q: Does it support MongoDB?
A: Prisma supports MongoDB with a different syntax. The generated models work with relational databases (PostgreSQL, MySQL, SQL Server, SQLite).

Related tools