19 lines
549 B
Python
19 lines
549 B
Python
"""One reading script's JSON object, which the host readings of this driver share."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import Any
|
|
|
|
|
|
def json_object(out: str, what: str) -> dict[str, Any]:
|
|
"""*out*, a script's ``ConvertTo-Json`` of one object, parsed.
|
|
|
|
:raises ValueError: when it is empty or no object, naming *what* was read.
|
|
"""
|
|
out = out.strip()
|
|
raw = json.loads(out) if out else None
|
|
if not isinstance(raw, dict):
|
|
raise ValueError(f"the {what} reading came back empty")
|
|
return raw
|