Hi All
I have written a little singleton object-package which can read in a JSON configuration file and then allows you to read various settings out of it.
It has a global handle: ghoJsonConfig and then a terse global method for getting back the settings: (Config({setting-path})).
From the header comments:
Code:
// Usage:
//
// Load the config file:
// Get LoadConfig of ghoJsonConfig {optional-filename} {optional-path} to bOK
//
// If not supplied the default filename is "config.json" and the path is the
// programs directory of your current workspace. If you pass an empty
// filename then "config.json:" will be used. There is no requirement for
// filename extension to be ".json" (although that _would_ seem sensible).
//
// Reading a setting:
// Move (Config("foo.bar.baz[3].bob")) to nVar // nVar is now 42
// Or:
// Get Config "foo.bar.baz[3].bob" to sVar // sVar is now "42"
//
// Which would return the setting in the file from:
// {
// "foo" : {
// "bar" : {
// "baz" : [
// 66,
// {
// "jim" : "jack"
// },
// false,
// {
// "bob" : 42 <--- This one!
// },
// {
// "kim" : "possible"
// }
// ]
// }
// }
// }
//
// (If "Config" conflicts with anything in your environment you can simply
// change the name of the global function at the bottom of the package.)
//
// It should handle multi-dimentional arrays (i.e. foo[3][22][6]) and JSON of
// arbitrary depth and length.
//
// Attempts to get settings which are not in the JSON will return empty strings.
//
// NOTE: JSON is case-sensitive, so your search-strings must exactly match the
// object names ("foo" is *not* "Foo") in the JSON file.
The package: JsonConfig.pkg
Please report bugs, errors, fun-had-with and most especially memory-leaks (I think it is being a good boy, but I've been wrong before!), etc. to MPeat at UnicornInterGlobal dot com.
Mike