In case of larger configs this can cause headaches. Points to the problematic part of the json config file while the pure-json example can’t tell you With json-cfg you get an exception with a message that What happens when you encounter an error.
MAILSPRING CONFIG.JSON LOCATION CODE
With json-cfg you can use extended syntax in the configįile and the code that loads/processes the config is also somewhat nicer but real difference is load_config ( 'server.cfg' ) for server in config. The same with json-cfg: import jsoncfg config = jsoncfg. get ( 'port', 8000 )) superuser_name = config load ( f ) for server in config : listen_on_interface ( server, server.
MAILSPRING CONFIG.JSON LOCATION HOW TO
This is how to load and process the above server configuration with a simple json library: import json with open ( 'server.cfg' ) as f : config = json. I assume that you have already installed json-cfg and you have the previously shown server configĮxample in a server.cfg file in the current directory. With config file line/column numbers only in case of json syntax errors (in best case).īy loading the json nodes/elements into our wrapper objects we can retain the line/column numbersįor the json nodes/elements and we can use them in our error messages in case of semantic errors.
This means that by using a simple json library you can report the location of errors Library is that the loaded json data doesn’t contain the line/column numbers for the loaded json One of the biggest problems with loading the config into bare python objects with a simple json At the same time if youĪre looking for a value that doesn’t exist in the config then these problems are handled withĮxceptions that contain line/column number info about the location of the error. Objects that help you to query the config with much nicer syntax. jsoncfg.load_config() and jsoncfg.loads_config() load the json data into special wrapper.These functions allow you to load config files into bare python representation of the jsonĭata (dictionaries, lists, numbers, etc…). jsoncfg.load() and jsoncfg.loads() are very similar to the standard json.loads().Similar to the standard json.loads() and another one that returns the json wrapped into specialĬonfig nodes that make handling the config file much easier: The json-cfg library provides two modes when it comes to loading config files: One that is very The location of the error in the config file). Only while parsing the file but also when processing/interpreting it.Ī simple config query syntax that handles default values, required elements andĪutomatically raises an exception in case of error (with useful info including Providing line number information for each element of the loaded config fileĪnd using this to display useful error messages that help locating errors not