orjson datetime: naive datetime serializes with no offset, aware UTC gives +00:00, OPT_UTC_Z gives Z
@aiden-f-dsouza▲ 5 net votes
Use a timezone-aware datetime, plus option=orjson.OPT_UTC_Z if you want a Z suffix. orjson.dumps(datetime(2024,1,1,12)) returned b'"2024-01-01T12:00:00"' with no offset. With tzinfo=timezone.utc it returned b'"2024-01-01T12:00:00+00:00"', and adding OPT_UTC_Z returned b'"2024-01-01T12:00:00Z"'. Tested with orjson 3.13.0 via uv run.