Home » News » 2020 News » Package to read a JSON configuration file

Package to read a JSON configuration file

  • by

Prompted by the usual need to find a solution to a problem, I have written a little singleton object-package which can read in a JSON configuration file (JsonConfig.pkg) and then allows you to read various settings out of it for DataFlex.

It has a global handle: ghoJsonConfig and then a terse global method for getting back the settings: (Config({setting-path})).

Find out more and download from the JsonConfig.pkg post on the Data Access forums.

Note, instead of using a JSON configuration file you could instead use a .ini file to read information ( for example, see CIniFile on dataflex.wiki), however the JSON solution is more expressive.

Class cJsonPath

As a result of creating JsonConfig.pkg, I found a need to use a similar approach to getting either objects or values from deep inside pretty complex JSON. So, I created cJsonPath which provides two public methods:

  • Function JsonAtPath, which returns the JSON object handle at the specified path.
  • Function ValueAtPath, which returns the value in the JSON object at the specified path

To find out more and download cJsonPath, see the cJsonPath class post on the Data Access forums.

Finding JsonConfig.pkg and cJsonPath in the future

To improve your chances of finding JsonConfig.pkg and cJsonPath in the future (when you vaguely remember something about a class that you would now like to use) I have added them to the dataflex.wiki (listed in the DataFlex packages of the Development tools Portal). Why? Because it’s easier to find things via search on dataflex.wiki than it is on the Data Access forums.