Framework: packages:json config - x684867/nemesis_server GitHub Wiki

PURPOSE:

JSON-config.js extends the JSON object to provide tools for validating, managing and interacting
with JSON-based configuration files.

FILES:

Filename Description
JSON-config.js Standalone JavaScript File

DESIGN NOTES

Package Configuration

No configuration exists.

Usage Notes

  • To load the utility--
require('JSON-config.js')();
* After loading the utility, set a pattern JSON object--
JSON.config.pattern={
     "myObject":{
          "myProperty":'string',
          "myOtherProperty":'number',
          "myNestedObject":{
               "myProperty":'boolean'
          },
     "myLastProperty":'string'
};
* Once a pattern is loaded, it can be tested--
if(JSON.config.isValid(myJSONinstance)) console.log("I am valid");

Theory of Operation

*When the user defines a pattern JSON object, specifying each property or other element of a given JSON configuration object to be inspected, the JSON.config.pattern setter will "decay" the JSON pattern object into a descriptive array (internally called arrPattern).

*When the user then asks JSON.config.isValid(jsonObject) to inspect jsonObject, a recursive loop inspects the jsonObject structure, comparing it to the decayed pattern (arrPattern) to determine if objectJSON syntactically matches. If so, then true is returned. Otherwise a big fat false is returned.

*It's that simple.

⚠️ **GitHub.com Fallback** ⚠️