remotion-dev/remotion · error · TypeError

Object of type {obj.__class__.__name__} is not JSON serializ

Error message

Object of type {obj.__class__.__name__} is not JSON serializable

What it means

Raised by the custom JSON serializer (_custom_serializer) when an object passed to json.dumps(default=...) is not an Enum, dataclass, plain __dict__ object, or non-string iterable. The serializer is the fallback for unknown types; if it still cannot convert, this TypeError fires during render-request construction.

Source

Thrown at packages/lambda-python/remotion_lambda/remotionclient.py:528

                f"Unexpected Lambda response format: {result_raw}"
            )

        return decoded_result

    def _custom_serializer(self, obj: Any) -> Any: # Added type hints
        """A custom JSON serializer that handles enums and objects."""
        if isinstance(obj, Enum):
            return obj.value if hasattr(obj, 'value') else obj.name
        # Check if it's a dataclass instance before calling asdict
        # This often works better with mypy than just a try-except.
        if hasattr(obj, '__dataclass_fields__'):
            return asdict(obj)
        if hasattr(obj, '__dict__'):
            return obj.__dict__
        if hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes, bytearray)):
            return list(obj)

        raise TypeError(
            f"Object of type {obj.__class__.__name__} is not JSON serializable"
        )

    def construct_render_request(
        self,
        render_params: Union[RenderMediaParams, RenderStillParams],
        render_type: RenderType,
    ) -> str:
        """
        Construct a render request in JSON format.

        Args:
            render_params (Union[RenderMediaParams, RenderStillParams]): Render parameters.
            render_type (RenderType): The type of render (video-or-audio or still).

        Returns:
            str: JSON representation of the render request.
        """

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Convert the offending object to a primitive (int/float/str/list/dict) before passing it as input props.
  2. For bytes, encode as base64: base64.b64encode(b).decode().
  3. For numpy/pandas, call .item() or .isoformat() to get a native Python primitive.
  4. Run json.dumps(input_props, default=str) locally first to surface the offending path.

Example fix

// before
input_props = {
    'image': raw_bytes,            # bytes - not handled
    'value': numpy.float64(3.14),  # numpy scalar - not handled
}
client.render_media(comp, input_props=input_props)

# after
import base64
input_props = {
    'image': base64.b64encode(raw_bytes).decode(),
    'value': float(numpy.float64(3.14)),
}
client.render_media(comp, input_props=input_props)
Defensive patterns

Strategy: type-guard

Validate before calling

import json
def preflight_props(props):
    json.dumps(props, default=lambda o: f'<unserializable:{type(o).__name__}>')
    return props

Type guard

def is_json_safe(value, _seen=None):\n    _seen = _seen or set()\n    if id(value) in _seen:\n        return False\n    if isinstance(value, (str, int, float, bool, type(None))):\n        return True\n    if isinstance(value, bytes):\n        return False\n    _seen.add(id(value))\n    if isinstance(value, dict):\n        return all(is_json_safe(v, _seen) for v in value.values())\n    if isinstance(value, (list, tuple)):\n        return all(is_json_safe(v, _seen) for v in value)\n    # unknown objects are not safe by default\n    return False

Try / catch

try:\n    client.render_media(...)\nexcept TypeError as e:\n    log.error('Non-serializable input: %s', e)\n    raise

Prevention

When it happens

Trigger: Passing inputProps (or render params) containing objects the serializer cannot handle: e.g. numpy scalars, pandas Timestamp, bytes objects, custom classes without __dict__, lambdas, file handles, or objects whose __dict__ itself contains non-serializable values.

Common situations: Data-science pipelines passing numpy/pandas objects directly; bytes payloads instead of base64 strings; file handles; SQLAlchemy columns; objects with __slots__ instead of __dict__.

Related errors


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/bf734c8051074cef. Report an issue: GitHub.