joi2json

Joi ⇄ JSON-Schema Converter

Usage no npm install needed!

<script type="module">
  import joi2json from 'https://cdn.skypack.dev/joi2json';
</script>

README

Joi ⇄ JSON-Schema Converter

JavaScript Style Guide Build Status npm download

JSON Schema and Joi converter Forked from joi-to-json-schema and enjoi

Install

  $ npm install joi2json --save

Usage

  const parser = require('joi2json')

  const schema = {
    "title": "Person",
    "type": "object",
    "properties": {
        "firstName": {
            "type": "string"
        },
        "lastName": {
            "type": "string"
        },
        "age": {
            "description": "Age in years",
            "type": "integer",
            "minimum": 0
        }
    },
    "required": ["firstName", "lastName"]
  }

  // JSON Schema to Joi
  const joiObj = parser.enjoi(schema)

  // Joi to JSON Schema
  const jsonSchema = parser.dejoi(joiObj)