Skip to content

A tiny library to validate json-ld documents using ld-query

Notifications You must be signed in to change notification settings

goofballLogic/ld-validate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ld-validate

A tiny library to validate json-ld documents using ld-query

Examples

Passing

    const jsonld = require( "jsonld" );
    const sample = require( "./valid-choir.json" );
    jsonld.expand( sample, ( e, expanded ) => { 
        
        const ldvalidate = require( ".." );
        const schemas = require( "../schema" );
        const context = schemas[ "context" ];
        const validate = ldvalidate( schemas, context );
        validate( "choir", expanded, e => {
            
            if ( e ) { console.error( e ); } else {
                
                console.log( "Validated ok" );
                
            }
            
        } );
        
    } );

$ node ./sample/valid-choir-validate.js

Validated ok

Failing


    const jsonld = require( "jsonld" );
    const sample = require( "./invalid-choir.json" );
    jsonld.expand( sample, ( e, expanded ) => { 
        
        const ldvalidate = require( ".." );
        const schemas = require( "../schema" );
        const context = schemas[ "context" ];
        const validate = ldvalidate( schemas, context );
        validate( "choir", expanded, e => {
            
            if ( e ) { console.error( e ); } else {
                
                console.log( "Validated ok" );
                
            }
            
        } );
        
    } );

$ node ./sample/invalid-choir-validate.js

[Error: Type of "country" is incorrect. Query was '> addressCountry @value'. Expected: string. Actual: number]

About

A tiny library to validate json-ld documents using ld-query

Resources

Stars

Watchers

Forks

Packages

No packages published