JSON to Prisma Schema

Infer Prisma models from JSON.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Paste a flat JSON object and get a Prisma model whose fields are typed from the values: String, Int, Float and Boolean, with Json for arrays and nested objects. It also adds an id field using cuid(). Treat it as a first draft.

How to use

1
Step 1
Paste one JSON object that represents a single row.
2
Step 2
Press Run.
3
Step 3
Copy the model into schema.prisma, rename it from Model, then add relations, optional fields and indexes.

How it works

Each top-level key becomes a field: strings map to String, whole numbers to Int, decimals to Float, booleans to Boolean, and arrays and objects to Json. The tool always begins the model with id String @id @default(cuid()). The model is named Model.

Worked example

A blog post

Input
{"title":"Hello","views":10,"rating":4.5,"published":true,"tags":["a"]}
Output
model Model { id String @id @default(cuid()) title String views Int rating Float published Boolean tags Json }
Walkthrough
tags is an array, so it becomes a Json column. You may prefer String[] or a relation to a Tag model.

Limitations

  • An id String field with cuid() is added only when your JSON has no id key; an existing id becomes the @id (autoincrement for integers).
  • Null values and fields missing from some items become optional (?). No relations, enums or @unique are generated; keys that are not valid names are renamed with @map.
  • A root value that is not an object returns a comment instead of a model.
  • Dates arrive as strings in JSON and become String, not DateTime.

Questions

Can I generate a Prisma schema from JSON?
Yes, as a starting point. Paste one object and press Run to get a model with typed fields.
What Prisma type does an array get?
Json. Change it to a scalar list or a relation if that fits your database.
Why does the model have an id field I did not provide?
The tool always adds id String @id @default(cuid()). Remove it if your data supplies its own key.
Will dates become DateTime?
No. JSON dates are strings, so they become String. Change them to DateTime by hand.

Features

  • Scalar type mapping
  • Json for arrays and objects
  • Auto id with cuid()
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • What Is A RESTful API?

    Traversy Media

    Most APIs exchange JSON—context for pretty-print and schema checks.

    Watch on YouTube
  • Inspect Network Activity - Chrome DevTools 101

    Chrome for Developers

    Debugging payloads you paste into JSON and JWT tools.

    Watch on YouTube