# json-to-prisma-schema-convertor **Repository Path**: mirrors_sync/json-to-prisma-schema-convertor ## Basic Information - **Project Name**: json-to-prisma-schema-convertor - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-09 - **Last Updated**: 2024-11-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # JSON to Prisma Schema Convertor [](https://badge.fury.io/js/json-to-prisma-schema-convertor) [](https://www.npmjs.com/package/json-to-prisma-schema-convertor) [](http://hits.dwyl.com/omar-dulaimi/json-to-prisma-schema-convertor) [](LICENSE) Convert your [JSON](https://json-schema.org) schema to an approximate [Prisma](https://github.com/prisma/prisma) Schema.
## Table of Contents - [Installation](#installing) - [Usage](#usage) ## Installation Using npm: ```bash npm install json-to-prisma-schema-convertor ``` Using yarn: ```bash yarn add json-to-prisma-schema-convertor --dev ``` # Usage 1- Star this repo 😉 2- Either use npx, or add an npm script like this: ```json { "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 ```json { "$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 ```prisma 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