# Datetime is not json serializable

**URL:** <https://community.temporal.io/t/datetime-is-not-json-serializable/18278>\
**Category:** Community Support\
**Tags:** python-sdk\
**Created:** [August 29, 2025, 6:28pm UTC](https://community.temporal.io/t/datetime-is-not-json-serializable/18278 "2025-08-29T18:28:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![synfinatic](https://avatars.discourse-cdn.com/v4/letter/s/85e7bf/32.png) [@synfinatic](https://community.temporal.io/u/synfinatic)\
**Post date:** [August 29, 2025, 6:28pm UTC](https://community.temporal.io/t/datetime-is-not-json-serializable/18278/1 "2025-08-29T18:28:55Z")

</div>

any ideas how to support datetime objects in python? normally I just use `@dataclass_json` to serialize properly, but that isn’t working with temporal.

```python
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from datetime import datetime

@dataclass_json
@dataclass
class TestJson:
    datetime: datetime = field(default_factory=lambda: datetime.now())
    name: str = field(default=‘test’)

@workflow.defn
class TestJsonWorkflow:
    @workflow.run
    async def run(self) → TestJson:
        return TestJson()

```

will throw: `TypeError: Object of type datetime is not JSON serializable`

```python
@pytest.mark.asyncio
async def test_json_test_workflow(client: Client):
    task_queue = 'test-json-test'
    async with Worker(
        client,
        task_queue=task_queue,
        workflows=[TestJsonWorkflow],
    ):
        handle = await client.start_workflow(
            TestJsonWorkflow.run,
            execution_timeout=timedelta(seconds=1),
            id=str(uuid.uuid4()),
            task_queue=task_queue,
        )
        result = await handle.result()
        assert result.name == "test"
        assert result.datetime < datetime.now()

```

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [September 1, 2025, 12:50pm UTC](https://community.temporal.io/t/datetime-is-not-json-serializable/18278/2 "2025-09-01T12:50:43Z")

</div>

Hi

I believe you have to use a Pydantic data converter [GitHub - temporalio/sdk-python: Temporal Python SDK](https://github.com/temporalio/sdk-python?tab=readme-ov-file#data-conversion)

---

<div class="post-metadata">

**Author:** ![synfinatic](https://avatars.discourse-cdn.com/v4/letter/s/85e7bf/32.png) [@synfinatic](https://community.temporal.io/u/synfinatic)\
**Post date:** [September 1, 2025, 4:17pm UTC](https://community.temporal.io/t/datetime-is-not-json-serializable/18278/3 "2025-09-01T16:17:20Z")

</div>

page not found: [https://github.com/temporalio/samples-python/tree/main/pydantic\_converter/v1](https://github.com/temporalio/samples-python/tree/main/pydantic_converter/v1)

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [September 1, 2025, 4:36pm UTC](https://community.temporal.io/t/datetime-is-not-json-serializable/18278/4 "2025-09-01T16:36:32Z")

</div>

> **[samples-python/pydantic\_converter at main · temporalio/samples-python](https://github.com/temporalio/samples-python/tree/main/pydantic_converter)**
>
> Samples for working with the Temporal Python SDK. Contribute to temporalio/samples-python development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![synfinatic](https://avatars.discourse-cdn.com/v4/letter/s/85e7bf/32.png) [@synfinatic](https://community.temporal.io/u/synfinatic)\
**Post date:** [September 2, 2025, 11:54pm UTC](https://community.temporal.io/t/datetime-is-not-json-serializable/18278/5 "2025-09-02T23:54:22Z")

</div>

ah, this is what i needed since we’re currently pinned to v2 [samples-python/pydantic\_converter\_v1 at main · temporalio/samples-python · GitHub](https://github.com/temporalio/samples-python/tree/main/pydantic_converter_v1)
