js6

js-schema-6901

Enhances js-schema with JSON Pointer (RFC 6901)

Showing:

Popularity

Downloads/wk

4

GitHub Stars

0

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

2

Size (min+gzip)

5.1KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

js-schema-6901 Build status

JSON Pointer, RFC 6901, defines a string syntax for identifying a specific value within a JavaScript Object Notation (JSON) document. For example, evaluating "foo/0/bar" against { foo: [ { bar: 1}, { bar: 2} } returns 1;

js-schema is simple and intuitive object validation library. It provides support for JSON Schema.

This package reports schema validation errors with a JSON Pointer to the offending field by adding the jpErrors method to a schema.

Getting started npm version

Install with $ npm install js-schema-6901. Bower will be coming soon.

Usage

var schema = require('js-schema-6901');
var person = schema({
    name: String,
    dob: /\d{4}\-\d{2}\-\d{2}/,
    children: Array.of(schema.self)
});

var badboy = {
    name: 'me', 
    children: [
        {dob: '2000-01-01', children: []}, 
        {dob: '2000-1-01'}
]};

console.log(person.jpErrors(badboy));

produces

{ 
   '/dob': 'key is not present in the object',
   '/children/0/name': 'key is not present in the object',
   '/children/1/name': 'key is not present in the object',
   '/children/1/dob': '2000-1-01 is not matched with RegExp -> /\\d{4}\\-\\d{2}\\-\\d{2}/',
   '/children/1/children': 'key is not present in the object' }
}

License

The MIT license

Copyright © 2015 Richard Schneider (makaretu@gmail.com)

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100