JSON to Prisma Schema
Infer Prisma models from JSON.
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
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?
What Prisma type does an array get?
Why does the model have an id field I did not provide?
Will dates become DateTime?
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 YouTubeInspect Network Activity - Chrome DevTools 101
Chrome for Developers
Debugging payloads you paste into JSON and JWT tools.
Watch on YouTube
- web.dev
Google
Modern web guidance that pairs with encoding and tooling pages.
- Getting started with JSON Schema
JSON Schema
When you outgrow ad-hoc validation and need a schema definition.