Results 1 to 8 of 8

Thread: JsonConfig.pkg

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    1,520

    Default JsonConfig.pkg

    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
    Attached Files Attached Files
    Last edited by Mike Peat; 4-Feb-2020 at 02:32 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •