Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

joi-json

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi-json

Builds Joi schemas from JSON objects

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status npm version

Joi-JSON

Creates Joi based object schemas from JSON.

Features

  • Create Joi schemas from JSON data
  • Express simple schemas using a single string
  • Works with LOV
  • Lightweight with minimal dependencies
  • Compatible with most of the Joi API
  • Node.js 6.10.0 compatible for use in AWS Lambda environments

Installation

Install via npm.

npm install joi-json --save

Note: joi or lov should also be installed

Getting Started

'use strict';

const builder = require( 'joi-json' ).builder();

let jsonSchema = {

    firstName: 'string:min=1,max=60,required',  // string using string-based notation

    lastName: { // string using object notation

        '@type': 'string',
        min: 1,
        max: 60,
        required: true
    },

    address: {  // address is an object (i.e. joi.object() )

        street: 'string:min=1,max=80,required',
        street2: 'string:min=1,max=80',
        city: 'string:min=1,max=40,required',
        state: 'string:min=1,max=40,required',
        postal: 'string:min=1,max=20,required',

        '@required': true   // needs the '@' to indicate that "required" is a property
    },

    // alternative values (i.e. joi.alternatives().try() )
    favNumberOrWord: [

        'string:min=1,max=10',
        'number:min=0,max=100'
    ]
};

let schema = builder.build( jsonSchema );

Which would yield the equivalent to the following joi schema:


const joi = require( 'joi' );

let schema = {

    firstName: joi.string().min(1).max(60).trim().required(),

    lastName: joi.string().min(1).max(60).trim().required(),

    address: Object.keys( {

            street: joi.string().min(1).max(80).trim().required(),
            street2: joi.string().min(1).max(80).trim(),
            city: joi.string().min(1).max(40).trim().required(),
            state: joi.string().min(1).max(40).trim().required(),
            postal: joi.string().min(1).max(20).trim().required()

        }).required(),

    favNumberOrWord: [

            joi.string().min(1).max(10).trim(),
            joi.number().min(1).max(100)
        ]
};

Documentation

For information on how to use Joi-JSON, please see our API documentation

Feedback

We'd love to get feedback on how to make this tool better. Feel free to contact us at feedback@vandium.io

License

BSD-3-Clause

Keywords

FAQs

Package last updated on 26 Sep 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc