Socket
Socket
Sign inDemoInstall

ak-json-to-joi

Package Overview
Dependencies
5
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ak-json-to-joi

[![npm version](https://badge.fury.io/js/ak-json-to-joi.svg)](https://badge.fury.io/js/ak-json-to-joi) [![Dependencies](https://david-dm.org/arshadkazmi42/ak-json-to-joi.svg)](https://david-dm.org/arshadkazmi42/ak-json-to-joi) [![npm Downloads](https://im


Version published
Maintainers
1
Install size
361 kB
Created

Readme

Source

ak-json-to-joi

NPM Module to convert predefined JSON into Joi validation schema dynamically.

Codacy Badge npm version Dependencies npm Downloads

How to install?

NPM

How to use


const JoiSchemaBuilder = require('ak-json-to-joi');
let JoiValidationSchema = JoiSchemaBuilder.build(yourJSON);
let result = Joi.validate(yourPayloadJSON, JoiValidationSchema)

Supported Features

Types

Use any of these as types of the key


string
number
email
array
object
boolean

Validations


minLength: {integer value}
maxLength: {integer value}
optional: {true / false}
required: {true / false}
regex: {regex pattern}
default: {default value}

Sample JSONs

ARRAY JSON


{
    "$array": {
        "name":{
            "$type":"string"
        },
        "number":{
            "$type":"number",
            "optional": true
        }
    }
}

OBJECT JSON


{
    "name": {
        "original": {
            "$type": "string",
            "required": true,
            "maxLength": 200
        },
        "nick": {
            "$type": "string",
            "optional": true,
            "default": "arshad"
        }
    },
    "phone": {
        "$type": "number",
        "required": true
    },
    "email": {
        "$type": "email",
        "optional": true
    },
    "date": {
        "$type": "date",
        "minDate": "1-1-2017",
        "maxDate": "10-05-2018"
    }
}

Note:


'type' and 'array' key in validation json should be prefixed with '$' symbol
on missing $ symbol your validation might not work.

Contributors

Keywords

FAQs

Last updated on 11 Nov 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc