Skip to content

Commit 9d36df5

Browse files
committed
Close #204: JSON serialize datetime.date() values
1 parent d84e8d3 commit 9d36df5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [UNRELEASED]
99

10+
* `datetime.date()` values are properly JSON serialized. (#204)
1011

1112
## [0.6.2] - 2025-05-21
1213

shinywidgets/_serialization.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numbers
44
import warnings
55
from binascii import b2a_base64
6-
from datetime import datetime
6+
from datetime import date, datetime
77
from typing import Iterable
88

99
from dateutil.tz import tzlocal
@@ -31,6 +31,9 @@ def json_default(obj: object) -> object:
3131
obj = _ensure_tzinfo(obj)
3232
return obj.isoformat().replace("+00:00", "Z")
3333

34+
if isinstance(obj, date):
35+
return obj.isoformat()
36+
3437
if isinstance(obj, bytes):
3538
return b2a_base64(obj).decode("ascii")
3639

0 commit comments

Comments
 (0)