Skip to content

y5gfunc.source.wobbly.io.json

json

JSON handling with orjson optimization.

Functions:

Name Description
load_json

Load JSON file with orjson for better performance

dump_json

Dump data to JSON string with orjson

load_project

Load and parse a Wobbly project file

load_json

load_json(file_path: Union[str, Path]) -> dict[str, Any]

Load JSON file with orjson for better performance

Parameters:

Name Type Description Default

file_path

Union[str, Path]

Path to JSON file

required

Returns:

Type Description
dict[str, Any]

Parsed JSON data

Source code in y5gfunc/source/wobbly/io/json.py
def load_json(file_path: Union[str, Path]) -> dict[str, Any]:
    """
    Load JSON file with orjson for better performance

    Args:
        file_path: Path to JSON file

    Returns:
        Parsed JSON data
    """
    with open(file_path, "rb") as f:
        return orjson.loads(f.read())

dump_json

dump_json(data: dict[str, Any]) -> bytes

Dump data to JSON string with orjson

Parameters:

Name Type Description Default

data

dict[str, Any]

Data to serialize

required

Returns:

Type Description
bytes

JSON bytes

Source code in y5gfunc/source/wobbly/io/json.py
def dump_json(data: dict[str, Any]) -> bytes:
    """
    Dump data to JSON string with orjson

    Args:
        data: Data to serialize

    Returns:
        JSON bytes
    """
    return orjson.dumps(data)

load_project

Load and parse a Wobbly project file

Parameters:

Name Type Description Default

project_path

PathLike

Path to Wobbly project file

required

Returns:

Type Description
Result[ProjectData]

Result containing project data if successful

Source code in y5gfunc/source/wobbly/io/json.py
def load_project(project_path: PathLike) -> Result[ProjectData]:
    """
    Load and parse a Wobbly project file

    Args:
        project_path: Path to Wobbly project file

    Returns:
        Result containing project data if successful
    """
    try:
        project = load_json(project_path)
        return Result.ok(project)
    except Exception as e:
        return Result.err(f"Failed to read or parse Wobbly project file: {e}")