MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / _json_safe

Function _json_safe

src/server/agent_server.py:1739–1751  ·  view source on GitHub ↗

Recursively coerce ``obj`` into a JSON-serializable structure. Unknown/opaque values (functions, dataclasses, …) degrade to ``str`` so a single bad field never makes the WS pump's ``json.dumps`` raise.

(obj: Any)

Source from the content-addressed store, hash-verified

1737
1738
1739def _json_safe(obj: Any) -> Any:
1740 """Recursively coerce ``obj`` into a JSON-serializable structure.
1741
1742 Unknown/opaque values (functions, dataclasses, …) degrade to ``str`` so a
1743 single bad field never makes the WS pump's ``json.dumps`` raise.
1744 """
1745 if obj is None or isinstance(obj, (bool, int, float, str)):
1746 return obj
1747 if isinstance(obj, Mapping):
1748 return {str(k): _json_safe(v) for k, v in obj.items()}
1749 if isinstance(obj, (list, tuple)):
1750 return [_json_safe(v) for v in obj]
1751 return str(obj)
1752
1753
1754def _current_mode(tool_context: Any, default: str) -> str:

Callers 1

_emitMethod · 0.85

Calls 1

itemsMethod · 0.80

Tested by

no test coverage detected