Test if the given JSON matches a certain structure.
- Very simple structure-describing rules.
- Structure describer itself is a valid JSON
var JSM=require('./js-structure-match.js');
var jm=new JSM({a:'int',
b:'string',
c:'float',
d:[{a:'int',b:'string'}],
e:{a:'int',
b:'string'}})
console.log(jm.match({a:1,
b:'hello',
c:2.3,
d:[{a:1,b:'meow'},
{a:233,b:'meowmeow'}],
e:{a:1,
b:'meowmeow'}}))Let's say we are matching data data to the structure structure
var JSM=require('./js-structure-match.js');
var jm=new JSM(structure);
console.log(jm.match(data));The output will be true when following rules are satisfied:
structureanddataare both arrays anddata[i]matchesstructure[0]for eachistructureanddataare both objects, and for every keykeyofstructure,datahave a key namedkeyanddata[key]matchesstructure[key]structure=='int'anddatais a intstructure=='float'anddatais a numberstructure=='string'anddatais a string
- Test if
structureis valid - npm repository