New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

praetorian

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

praetorian

A structured JSON parser and validator

  • 0.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30
increased by2900%
Maintainers
1
Weekly downloads
 
Created
Source

Praetorian

Praetorian is a structured JSON validator. It take both a JSON data set and a structure and tells you if anything, whats wrong with it.

Installation

$ npm install praetorian

Schema

Example:

{
    "shield": {
        "required": true
        "validation": {

        }
    },
    "weapon": {
        "required": true
        "type": "array",
        "items": {
            "sword": {
                "validation": {

                }
            },
            "dagger": {
                "required": true
            }
        }
    },
    "helmet": {
        "type": "object",
        "properties": {
            "noseGuard": {
                "required": true
            },
            "chinStrap": {

            }
        }
    }
}

Notes:

  • By specifying "type", Praetorian will automatically cast values
  • Objects have "properties"
  • Arrays have "items"
  • Validation configuration should be used to ensure any type dependencies are met

Usage

var Praetorian = require( '../index' );
praetorian = new Praetorian();

// pass your data and structure in like this
praetorian.validate( data, structure, function( err, data ) {
    if( err ) {
        console.log( 'check err', err );
        // requirements will tell you for the passed structure
        // how to fulfill the validation
        praetorian.requirements( structure, function( err, data ) {
            if( err ) {
                // console.log( 'requirements err', err );
            } else {
                // console.log( 'requirements success', data );		
            }
        } );
    } else {
        console.log( 'check success', data );
    }
} );

Testing

To run the test harness do the following:

cd praetorian
node test/sanity.js

License

MIT

FAQs

Package last updated on 28 Nov 2013

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