moobius.json_utils#
Module-level functions#
marked_recursive_dataclass#
Recursively converts nested lists, dicts, etc into dataclasses if they have been markd with types._DTYPE and types._DVAL.
**marked_recursive_dataclass**(data)
__data:__ Data.
The dataclassed data. Used for JSON loading.
Used by json_utils.enhanced_json_load.
(this function does not raise any notable errors)
marked_recursive_undataclass#
Converts data containing dataclasses back into pure dicts, making them with json_utils._DTYPE and json_utils._DVAL..
**marked_recursive_undataclass**(data, typemark_dataclasses)
__data:__ Dataclassed data.
__typemark_dataclasses:__ Whether to mark dataclasses in a special way so they are known as such.
The non-dataclassed data.
Used by json_utils.enhanced_json_save.
(this function does not raise any notable errors)
enhanced_json_load#
Loads JSON from the disk,.
**enhanced_json_load**(filename)
__filename:__ Filename or bytes.
The possibly-nested datastructure which may have Dataclasses.
(this function does not raise any notable errors)
enhanced_json_save#
Saves the JSON to the disk and/or a string.
**enhanced_json_save**(filename, data, typemark_dataclasses, indent)
__filename:__ The filename or file object to save to. None if not saving to any file.
__data:__ What needs to be saved. Can be a nested datastructure even with embedded dataclasses.
__typemark_dataclasses=True:__ Save dataclasses as special dicts so that on enhanced_json_load load they are converted back into dataclasses.
__indent=2:__ The indent to display the text at.
The data as a JSON string.
(this function does not raise any notable errors)
recursive_json_load#
Loads json files into dicts and lists, including dicts/lists of json filenames. Used for the app configuration. Strings anywhere in x that have no newlines and end in .json or .JSON will be treated like filenames. Does not use enhanced_json features..
**recursive_json_load**(x)
__x:__ Generic input x.
The modified input.
(this function does not raise any notable errors)
update_jsonfile#
Updates a json file. Uses enhanced_json_load (which makes dataclasses have metadata).
**update_jsonfile**(fname, key_path, value)
__fname:__ The json file.
__key_path:__ The path within the datastructure.
__value:__ The new value.
None.
(this function does not raise any notable errors)
get_config#
Calculates the configuration in various ways. Config files are automatically generated by quickstart.py which is invoked by running the command “moobius”. This may involve JSON file reading.
**get_config**(config, account_config, service_config, db_config, log_config)
__config=None:__ The entire config, a string (JSON filepath) or dict.
__account_config=None:__ The account-sepcific config with secrets, a string (JSON filepath) or dict.
__service_config=None:__ Service-specific config (the urls, the service id, and the channels).
__db_config=None:__ Config specific to the Moobius db engine. A list of attributes. This feature is an independent feature to the Platform.
__log_config=None:__ Config specific to logging. This feature is an independent feature to the Platform.
The config as a dict. Where to save the new service id as [json filename, datastructure_path], if there is a JSON file to save to.
(this function does not raise any notable errors)