Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

omar-dulaimi/json-to-prisma-schema-convertor

Repository files navigation

JSON to Prisma Schema Convertor

npm version npm HitCount npm

Convert your JSON schema to an approximate Prisma Schema.

Buy Me A Coffee

Table of Contents

Installation

Using npm:

 npm install json-to-prisma-schema-convertor

Using yarn:

 yarn add json-to-prisma-schema-convertor --dev

Usage

1- Star this repo πŸ˜‰

2- Either use npx, or add an npm script like this:

{
 "scripts": {
 "json-to-prisma": "json-to-prisma-schema-convertor convert --inputPath='./prisma/schema.json' --outputPath='./prisma/schema.prisma'"
 }
}

2- Running npm run json-to-prisma or npx json-to-prisma-schema-convertor convert --inputPath='./prisma/schema.json' --outputPath='./prisma/schema.prisma' for the following JSON schema

{
 "$schema": "http://json-schema.org/draft-07/schema#",
 "definitions": {
 "User": {
 "type": "object",
 "properties": {
 "id": {
 "type": "integer"
 },
 "createdAt": {
 "type": "string",
 "format": "date-time"
 },
 "email": {
 "type": "string"
 },
 "weight": {
 "type": ["number", "null"]
 },
 "is18": {
 "type": ["boolean", "null"]
 },
 "name": {
 "type": ["string", "null"]
 },
 "successor": {
 "anyOf": [
 {
 "$ref": "#/definitions/User"
 },
 {
 "type": "null"
 }
 ]
 },
 "predecessor": {
 "anyOf": [
 {
 "$ref": "#/definitions/User"
 },
 {
 "type": "null"
 }
 ]
 },
 "role": {
 "type": "string",
 "default": "USER",
 "enum": ["USER", "ADMIN"]
 },
 "posts": {
 "type": "array",
 "items": {
 "$ref": "#/definitions/Post"
 }
 },
 "keywords": {
 "type": "array",
 "items": {
 "type": "string"
 }
 },
 "biography": {
 "type": ["number", "string", "boolean", "object", "array", "null"]
 }
 }
 },
 "Post": {
 "type": "object",
 "properties": {
 "id": {
 "type": "integer"
 },
 "user": {
 "anyOf": [
 {
 "$ref": "#/definitions/User"
 },
 {
 "type": "null"
 }
 ]
 }
 }
 }
 },
 "type": "object",
 "properties": {
 "user": {
 "$ref": "#/definitions/User"
 },
 "post": {
 "$ref": "#/definitions/Post"
 }
 }
}

will generate the following Prisma schema

model Post {
 id Int
 user User?
}
model User {
 id Int
 createdAt DateTime
 email String
 weight Int?
 is18 Boolean?
 name String?
 successor User?
 predecessor User?
 role UserRole @default(USER)
 posts Post[]
 keywords String[]
 biography Json?
}
enum UserRole {
 USER
 ADMIN
}

Available Options

  • outputPath: string - path of the Json schema to convert

    • alias: op
    • required
  • inputPath: string - path of the prisma schema to be generated

    • alias: ip
    • required

About

Converts a Json schema to a Prisma schema

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /