{"record":{"id":"bf734c8051074cef","repo":"remotion-dev/remotion","slug":"object-of-type-obj-class-name-is-not-jso","errorCode":null,"errorMessage":"Object of type {obj.__class__.__name__} is not JSON serializable","messagePattern":"Object of type (.+?) is not JSON serializable","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/lambda-python/remotion_lambda/remotionclient.py","lineNumber":528,"sourceCode":"                f\"Unexpected Lambda response format: {result_raw}\"\n            )\n\n        return decoded_result\n\n    def _custom_serializer(self, obj: Any) -> Any: # Added type hints\n        \"\"\"A custom JSON serializer that handles enums and objects.\"\"\"\n        if isinstance(obj, Enum):\n            return obj.value if hasattr(obj, 'value') else obj.name\n        # Check if it's a dataclass instance before calling asdict\n        # This often works better with mypy than just a try-except.\n        if hasattr(obj, '__dataclass_fields__'):\n            return asdict(obj)\n        if hasattr(obj, '__dict__'):\n            return obj.__dict__\n        if hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes, bytearray)):\n            return list(obj)\n\n        raise TypeError(\n            f\"Object of type {obj.__class__.__name__} is not JSON serializable\"\n        )\n\n    def construct_render_request(\n        self,\n        render_params: Union[RenderMediaParams, RenderStillParams],\n        render_type: RenderType,\n    ) -> str:\n        \"\"\"\n        Construct a render request in JSON format.\n\n        Args:\n            render_params (Union[RenderMediaParams, RenderStillParams]): Render parameters.\n            render_type (RenderType): The type of render (video-or-audio or still).\n\n        Returns:\n            str: JSON representation of the render request.\n        \"\"\"","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/lambda-python/remotion_lambda/remotionclient.py#L510-L546","documentation":"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.","triggerScenarios":"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.","commonSituations":"Data-science pipelines passing numpy/pandas objects directly; bytes payloads instead of base64 strings; file handles; SQLAlchemy columns; objects with __slots__ instead of __dict__.","solutions":["Convert the offending object to a primitive (int/float/str/list/dict) before passing it as input props.","For bytes, encode as base64: base64.b64encode(b).decode().","For numpy/pandas, call .item() or .isoformat() to get a native Python primitive.","Run json.dumps(input_props, default=str) locally first to surface the offending path."],"exampleFix":"// before\ninput_props = {\n    'image': raw_bytes,            # bytes - not handled\n    'value': numpy.float64(3.14),  # numpy scalar - not handled\n}\nclient.render_media(comp, input_props=input_props)\n\n# after\nimport base64\ninput_props = {\n    'image': base64.b64encode(raw_bytes).decode(),\n    'value': float(numpy.float64(3.14)),\n}\nclient.render_media(comp, input_props=input_props)","handlingStrategy":"type-guard","validationCode":"import json\ndef preflight_props(props):\n    json.dumps(props, default=lambda o: f'<unserializable:{type(o).__name__}>')\n    return props","typeGuard":"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","tryCatchPattern":"try:\\n    client.render_media(...)\\nexcept TypeError as e:\\n    log.error('Non-serializable input: %s', e)\\n    raise","preventionTips":["Convert numpy/pandas values with .item() / .isoformat() before rendering.","Encode bytes as base64 strings before passing as input props.","Pre-serialize inputProps with json.dumps(default=str) to surface the offending path."],"tags":["python","serialization","json","input-props","type-error"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}