src.util.json_utils module¶
Utility functions for reading and manipulating json files
- src.util.json_utils.get_config_file_type(file_path: str) str [source]¶
Verify that configuration file is json or yaml
- src.util.json_utils.strip_comments(str_, delimiter=None)[source]¶
Remove comments from str_. Comments are taken to start with an arbitrary delimiter and run to the end of the line.
- src.util.json_utils.parse_json(str_)[source]¶
Parse JSONC (JSON with
//
-comments) string str_ into a Python object. Comments are discarded. Wraps standard libraryjson.loads()
.Syntax errors in the input (
JSONDecodeError
) are passed through from the Python standard library parser. We correct the line numbers mentioned in the errors to refer to the original file (i.e., with comments.)
- src.util.json_utils.read_json(file_path, log=<Logger>)[source]¶
Reads a struct from a JSONC file at file_path.
- Raises:
MDTFFileNotFoundError – If file not found at file_path.
- Returns:
dict – data contained in the file, as parsed by
parse_json()
.
Execution exits with error code 1 on all other exceptions.
- src.util.json_utils.find_json(file_path, exit_if_missing=True, log=<Logger>)[source]¶
Reads a JSONC file