Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:8beeeaaat Touchdesigner mcp Safe Serialize

From Leeroopedia
Knowledge Sources
Domains Serialization, JSON
Last Updated 2026-10-28 00:00 GMT

Overview

Concrete tool for recursively converting arbitrary TouchDesigner Python objects — including TD operators, Page, and Result wrappers — into JSON-safe primitives.

Description

safe_serialize is a recursive serializer that walks an object and produces a structure composed only of JSON-safe types (None, int, float, bool, str, list, dict). It special-cases Result objects (unwrapping success/data or error), TouchDesigner operators (calling obj.eval() for parameter values, or obj.path for OP references), Page objects, and generic objects via __dict__. Anything that cannot be converted falls back to str(obj). This is what allows the controller to json.dumps the response regardless of what the service layer returns.

Usage

Call safe_serialize on any service return value before passing it to json.dumps in the HTTP response path.

Code Reference

Source Location

Signature

def safe_serialize(obj: Any) -> Any: ...

Import

from utils.serialization import safe_serialize

I/O Contract

Inputs

Name Type Required Description
obj Any Yes Any Python object (TD OP, Result, dict, list, primitive, custom class)

Outputs

Name Type Description
return Any JSON-safe structure: None, int, float, bool, str, list, dict

Usage Examples

Serialize a service Result containing TD operators

from utils.serialization import safe_serialize
import json

result = {
    "success": True,
    "data": {
        "nodePath": "/project1/geo1",
        "parameters": [op("/project1/geo1").par.tx],  # TD Par object
    },
}
safe = safe_serialize(result)
# safe["data"]["parameters"][0] -> evaluated par value (float) or path string
json_str = json.dumps(safe)

Serialize a raw TD operator

# An OP with a .path attribute -> returns its path string
path_str = safe_serialize(op("/project1/geo1"))
assert path_str == "/project1/geo1"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment