jsjsonschema

1.1.7 • Public • Published

Javascript JSON Schema

Do you want to contribute with this project? Contact me: bw.bwctm@gmail.com

##Code example:

    var jsonschema = require('jsjsonschema');
    
    var article = {
        "$ref$": "article_1",
        "title": "This is an Article",
        "page": "ref(page_1)",
        "other": {
            "something": "ref(article_1)"
        }
    };
    
    var page = {
        "$ref$": "page_1",
        "title": "This is a page"
    };
    
    var articleSchema = {
        "id": "/ArticleSchema",
        "type": "object",
        "properties": {
            "title": {
                "type": "integer"
            },
            "page": {
                "type": "integer",
                "$ref$": "($ref$)"
            },
            "other": {
                "properties": {
                    "something": {
                        "type": "string",
                        "$ref$": "($ref$)"
                    }
                }
            }
        }
    };
    
    var pageSchema = {
        "id": "/PageSchema",
        "type": "object",
        "properties": {
            "title": {
                "type": "string"
            }
        }
    };
    
    jsonschema.addSchema('/ArticleSchema', articleSchema);
    jsonschema.addSchema('/PageSchema', pageSchema);
    
    jsonschema.addValidate('/ArticleSchema', article, 'article');
    jsonschema.addValidate('/PageSchema', page, 'page');
    
    jsonschema.start();
    
    console.log(jsonschema.getErrors());

Package Sidebar

Install

npm i jsjsonschema

Weekly Downloads

10

Version

1.1.7

License

ISC

Last publish

Collaborators

  • brenw