Skip to main content
added 2 characters in body
Source Link
Michael Dorner
  • 20.6k
  • 16
  • 95
  • 132

I usually use orjson. Not only because of its tremendous performance, but also for its great (RFC-3339 compliant) support of datetime:

import orjson # via pip3 install orjson from datetime import datetime data = {"created_at": datetime(2022, 3, 1)} orjson.dumps(data) # returns b'{"created_at":"2022-03-01T00:00:00"}' 

If you would like to use datetime.datetimedatetime.datetime objects without a tzinfo as UTC you can add the related option:

orjson.dumps(data, option=orjson.OPT_NAIVE_UTC) # returns b'{"created_at":"2022-03-01T00:00:00+00:00"}' 

I usually use orjson. Not only because of its tremendous performance, but also for its great (RFC-3339 compliant) support of datetime:

import orjson # via pip3 install orjson from datetime import datetime data = {"created_at": datetime(2022, 3, 1)} orjson.dumps(data) # returns b'{"created_at":"2022-03-01T00:00:00"}' 

If you would like to use datetime.datetime objects without a tzinfo as UTC you can add the related option:

orjson.dumps(data, option=orjson.OPT_NAIVE_UTC) # returns b'{"created_at":"2022-03-01T00:00:00+00:00"}' 

I usually use orjson. Not only because of its tremendous performance, but also for its great (RFC-3339 compliant) support of datetime:

import orjson # via pip3 install orjson from datetime import datetime data = {"created_at": datetime(2022, 3, 1)} orjson.dumps(data) # returns b'{"created_at":"2022-03-01T00:00:00"}' 

If you would like to use datetime.datetime objects without a tzinfo as UTC you can add the related option:

orjson.dumps(data, option=orjson.OPT_NAIVE_UTC) # returns b'{"created_at":"2022-03-01T00:00:00+00:00"}' 
edited body
Source Link
Michael Dorner
  • 20.6k
  • 16
  • 95
  • 132

I usually use orjson. Not only because of its tremendous performance, but also for its great (RFC-3339 complaintcompliant) support of datetime:

import orjson # via pip3 install orjson from datetime import datetime data = {"created_at": datetime(2022, 3, 1)} orjson.dumps(data) # returns b'{"created_at":"2022-03-01T00:00:00"}' 

If you would like to use datetime.datetime objects without a tzinfo as UTC you can add the related option:

orjson.dumps(data, option=orjson.OPT_NAIVE_UTC) # returns b'{"created_at":"2022-03-01T00:00:00+00:00"}' 

I usually use orjson. Not only because of its tremendous performance, but also for its great (RFC-3339 complaint) support of datetime:

import orjson # via pip3 install orjson from datetime import datetime data = {"created_at": datetime(2022, 3, 1)} orjson.dumps(data) # returns b'{"created_at":"2022-03-01T00:00:00"}' 

If you would like to use datetime.datetime objects without a tzinfo as UTC you can add the related option:

orjson.dumps(data, option=orjson.OPT_NAIVE_UTC) # returns b'{"created_at":"2022-03-01T00:00:00+00:00"}' 

I usually use orjson. Not only because of its tremendous performance, but also for its great (RFC-3339 compliant) support of datetime:

import orjson # via pip3 install orjson from datetime import datetime data = {"created_at": datetime(2022, 3, 1)} orjson.dumps(data) # returns b'{"created_at":"2022-03-01T00:00:00"}' 

If you would like to use datetime.datetime objects without a tzinfo as UTC you can add the related option:

orjson.dumps(data, option=orjson.OPT_NAIVE_UTC) # returns b'{"created_at":"2022-03-01T00:00:00+00:00"}' 
Source Link
Michael Dorner
  • 20.6k
  • 16
  • 95
  • 132

I usually use orjson. Not only because of its tremendous performance, but also for its great (RFC-3339 complaint) support of datetime:

import orjson # via pip3 install orjson from datetime import datetime data = {"created_at": datetime(2022, 3, 1)} orjson.dumps(data) # returns b'{"created_at":"2022-03-01T00:00:00"}' 

If you would like to use datetime.datetime objects without a tzinfo as UTC you can add the related option:

orjson.dumps(data, option=orjson.OPT_NAIVE_UTC) # returns b'{"created_at":"2022-03-01T00:00:00+00:00"}'