mth5.io.phoenix.readers.helpers
Helper utilities for Phoenix Geophysics reader module.
Created on Tue Jun 20 15:51:20 2023
@author: jpeacock
Functions
|
Read a JSON file directly into a SimpleNamespace object. |
Module Contents
- mth5.io.phoenix.readers.helpers.read_json_to_object(fn: str | pathlib.Path) types.SimpleNamespace[source]
Read a JSON file directly into a SimpleNamespace object.
- Parameters:
fn (str or Path) – Path to the JSON file to read.
- Returns:
Object containing the JSON data as attributes.
- Return type:
SimpleNamespace
- Raises:
FileNotFoundError – If the specified file does not exist.
json.JSONDecodeError – If the file contains invalid JSON.
IOError – If there’s an error reading the file.
Examples
>>> obj = read_json_to_object("config.json") >>> print(obj.some_attribute)
Notes
This function uses json.load with an object_hook to convert all dictionaries to SimpleNamespace objects, allowing dot notation access to nested JSON properties.