npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

json-blueprint

v1.0.31

Published

JSON validation library

Downloads

2

Readme

json-blueprint

JSON validation library

Quick look

import Blueprint from 'json-blueprint';

const person = new Blueprint('Test', {
   name: String,
   age: Number,
   verified: Boolean,
   phone: {
      ext: {
         type: String,
         maxLength: 5
      },
      number: Any.of(Number, String)
   },
   intrests: [ String ],
   planet: Is('Earth'),
   season: Is.oneOf('summer', 'winter', 'spring', 'fall'),
   songs: Array,
   contacts: Object,
   data: Any
});

person.validate({ ...object });

Installation

npm:

npm install json-blueprint

yarn:

yarn add json-blueprint

Usage

// Import the library
import Blueprint from 'json-blueprint';

// Create new blueprint
const bp = new Blueprint('BlueprintName', {...schema});

// or
const bp = Blueprint.create('BlueprintName' {...schema});


// Validate data
bp.validate({...data})

Table of contents

String

import Blueprint from 'json-blueprint';

const bp = new Blueprint('Test', {
   // Basic string
   name: String,
   
   // String with options
   username: {
      type: String,
      minLength: 3,
      maxLength: 5,

      // Regex match
      match: /[^A-Za-z0-9]+/g,

      // Additional validation funciton
      validate: (prop, value) => {
         if (!value.includes('clown')) {
            throw new Error('Clowns are scary');
         }
      },

      // Property is required by default
      required: false
   }
});

Number

import Blueprint from 'json-blueprint';

const bp = new Blueprint('Test', {
   // Basic number
   age: Number,
   
   // Number with options
   poolNumber: {
      type: Number,
      min: 0,
      max: 15,

      // Additional validation funciton
      validate: (prop, value) => {
         if (value === 8) {
            throw new Error(`8-Ball not allowed for the property ${prop}`);
         }
      },

      // Property is required by default
      required: false
   }
});

Boolean

import Blueprint from 'json-blueprint';

const bp = new Blueprint('Test', {
   // Basic boolean
   loggedIn: Boolean,
   
   // Boolean with options
   verified: {
      type: Boolean,

      // Additional validation funciton
      validate: (prop, value) => {
         if (!value) {
            throw new Error('User is not verified');
         }
      },

      // Property is required by default
      required: false
   }
});

Object

import Blueprint from 'json-blueprint';

const bp = new Blueprint('Test', {
   // Basic object
   roles: Object,

   // Object with defined properties
   hours: {
      partTime: Boolean,
      fullTime: Boolean,
      preferredHours: Array
   },
   
   // Object with options
   permissions: {
      type: Object,

      // Additional validation funciton
      validate: (prop, value) => {
         const keys = Object.keys(value);

         if (!keys.includes('read')) {
            throw new Error(`${prop} is missing read permission`);
         }
      },

      // Property is required by default
      required: false
   },

   // Object with options and defined properties
   salary: {
      type: Object,
      required: false,
      items: {
         hourlyRate: Number,
         currency: String
      }
   }
});

Array

import Blueprint from 'json-blueprint';

const bp = new Blueprint('Test', {
   // Any array
   favoriteSongs: Array,

   // Array of strings
   favoriteMovies: [ String ],

   // Array of objects
   accounts: [
      {
         id: String,
         name: String
      }
   ],

   // Array of string arrays
   tasksTable: [
      [ String ]
   ],
   
   // Array with options
   hobies: {
      type: Array,
      minLength: 1,
      maxLength: 5,

      // Additional validation funciton
      validate: (prop, value) => {
         if (!value) {
            throw new Error('User is not verified');
         }
      },

      // Property is required by default
      required: false
   },

   // Array with options and defined items
   technologies: {
      type: Array,
      required: false,
      items: String
   },
   addresses: {
      type: Array,
      minLength: 1,
      items: {
         street: String,
         number: String
      }
   }
});

Tuple

import Blueprint from 'json-blueprint';

const bp = new Blueprint('Test', {
   /**
    * Phone number tuple with extension and number
    * @param { string } [0]
    * @param { number } [1]
    */
   number: Tuple(String, Number)
});

Any and Any.of

import Blueprint from 'json-blueprint';

const bp = new Blueprint('Test', {
   // Any
   data: Any,

   // Any of the provided types
   apartmentNumber: Any.of(String, Number),

   phone: Any.of(String, Number, Tuple(String, Number), { ext: String, num: Number })
});

Is and Is.oneOf

import Blueprint from 'json-blueprint';

const bp = new Blueprint('Test', {
   // Any
   solarSystem: Is('Milky Way'),

   // Any of the provided types
   planet: Is.oneOf('Earth', 'Mars'),

   city: Is.oneOf('New York', [ 'New York' ], 10001, { country: 'USA', city: 'New York' });
});

Custom types

import Blueprint from 'json-blueprint';

// Define custom type which checks is provided value truthy
function Truthy (prop, value) {
   if (!value) {
      throw new Error(`${prop} is not truthy`);
   }
}

// Create blueprint whcich implements custom type
const bp = new Blueprint('Test', {
   person: {
      happy: Truthy
   }
});

// Validate object
bp.validate({
   person: {
      happy: 0
      // Test.person.happy is not truthy
   }
})

Custom type with options

import Blueprint from 'json-blueprint';

// Define custom type
function Truthy (prop, value, options) {
   const {
      a, // true
      b, // 1
      c, // 'hello'
      d  // { test: [] }
   } = options;

   if (!value) {
      throw new Error(`${prop} is not truthy`);
   }
}

// Create blueprint whcich implements custom type
const bp = new Blueprint('Test', {
   person: {
      happy: {
         type: Truthy,
         a: true,
         b: 1,
         c: 'hello',
         d: { test: [] }
      }
   }
});