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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsontron

v0.8.19

Published

Schematron based JSON Validator

Downloads

48

Readme

jsontron

Schematron based JSON Semantic Validator. JSON Semantic Rules Engine.

Installation

$ npm i jsontron

Note: If you have not installed node and npm. Please follow instructions at below site to install node and npm
https://docs.npmjs.com/getting-started/installing-node#installing-npm-from-the-nodejs-site

Documentation

Introduction, examples and tutorials:

https://amer-ali.github.io/jsontron/

Usage: Command Line

//go to the bin folder of jsontron module...

$ cd $JSONTRON_ROOT/bin
 
//run JSONValidator with instance doc, rules doc and optional phase list
//#ALL and #DEFAULT are special key words meant to invoke all or default phases respectively


$ node JSONValidator -i {instance doc} -r { rules doc} [#ALL | #DEFAULT | Phase List] [-d]

where:
 i is json instance document to be validated
 r is rules file
 #ALL | #DEFAULT | Phase list  specifies the phase (s)
 d is to enable debug
 
 //alternatively you can set an environment variable for JSONValidator like below
 //in Windows
 
 $ set JSONValidator = $JSONTRON_ROOT/bin/JSONValidator
 

//example
$ cd ../node_modules/jsontron/data/dissertation/phase

$ node %JSONValidator% -i loandata.json -r loandat-rulees_dissertation_singlePhase.json

Output

Parsing Pattern: patternid1
1 Pattern(s) Requested.
1 Pattern(s) Processed.
0 Pattern(s)  Ignored.
Report {
  errors: [],
  warnings: [],
  validations:
    [ { schRule: [Object],
       ruleContext: [Object],
       assertionid: 'assertidFHA21',
       assertionTest: 'jp.query(contextNode,\'$..amount\') <= 500000',
       message: 'successful',
       assertionValid: true } ] }
 true
 **** THIS INSTANCE IS SEMANTICALLY VALID ****

Usage: Inside other modules/scripts

var jsontron = require("jsontron");

myInstance = { "doc": {} };
myRules = {
"schema":{
"id":"eg3_1",
"title":"Technical document schema",
"schemaVersion":"ISO Schematron 2016",
"queryBinding":"jsonpath",
"defaultPhase":"phaseid1",
 "phase":[
	{
		"id":"phaseid1",
		"active":["Document_root"]
	}
], 
"pattern":[
  {
  	"id":"Document_root",
  	"title":"pattern title",
  	"rule":[
      {          
          	"id":"doc_root",
          	"abstract":false,
            "context": "$",
            "assert":[
              {
                 "id":"doc_root_assert",
                 "test":"contextNode.length ==1 && contextNode[0] == jp.parent(contextNode, '$..doc')",
                 "message": "Root element should be 'doc'."
              }
            ]              
      }]}]}};
      
      
//without phase
var myReport = jsontron.JSONTRON.validate(myInstance, myRules);
var valid = myReport.valid;

//with phase
var myReport = jsontron.JSONTRON.validate(myInstance, myRules, ['phaseid1']);
var valid = myReport.valid;
[Note: the phase(s) have to be in array format like ['phaseid1'] or ['phaseid2'] or ['phaseid1', 'phaseid2'] or ['#DEFAULT']   ]

Examples: Using IBM Examples from Command Line

//IBM Schematron examples translated from XML to JSON are bundled with the module in data/ibm-test-suite folder

// Below is an example using IBM Example 3.1
$cd $JSONTRON_ROOT\data\ibm-test-suite\3.1

$ node JSONValidator -i eg3_1_good1.json -r eg3_1-rules.json

Output

Parsing Pattern: Document_root
 1 Pattern(s) Requested.
1 Pattern(s) Processed.
0 Pattern(s)  Ignored.
 Report {
   errors: [],
   warnings: [],
   validations:
      [ { schRule: [Object],
       ruleContext: [Object],
       assertionid: 'doc_root_assert',
       assertionTest: 'contextNode.length ==1 && contextNode[0] == jp.parent(contextNode, \'$..doc\')',
       message: 'successful',
       assertionValid: true } ] }
true
**** THIS INSTANCE IS SEMANTICALLY VALID ****

Keywords

Schematron JSON Semantic-Validator JSON Co-constraints JSON-Rules-Engine