Skip to main content
Active reading [<https://en.wiktionary.org/wiki/dictionary#Noun>].
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

Here is my solution:

import json   class DatetimeEncoder(json.JSONEncoder): def default(self, obj): try: return super().default(obj) except TypeError: return str(obj) 

Then you can use it like that:

json.dumps(dictionnarydictionary, cls=DatetimeEncoder) 

Here is my solution:

import json   class DatetimeEncoder(json.JSONEncoder): def default(self, obj): try: return super().default(obj) except TypeError: return str(obj) 

Then you can use it like that:

json.dumps(dictionnary, cls=DatetimeEncoder) 

Here is my solution:

import json class DatetimeEncoder(json.JSONEncoder): def default(self, obj): try: return super().default(obj) except TypeError: return str(obj) 

Then you can use it like that:

json.dumps(dictionary, cls=DatetimeEncoder) 
deleted 29 characters in body
Source Link
Natim
  • 18.2k
  • 25
  • 101
  • 150

Here is my solution:

# -*- coding: utf-8 -*- import json class DatetimeEncoder(json.JSONEncoder): def default(self, obj): try: return super(DatetimeEncoder, obj).default(obj) except TypeError: return str(obj) 

Then you can use it like that:

json.dumps(dictionnary, cls=DatetimeEncoder) 

Here is my solution:

# -*- coding: utf-8 -*- import json class DatetimeEncoder(json.JSONEncoder): def default(self, obj): try: return super(DatetimeEncoder, obj).default(obj) except TypeError: return str(obj) 

Then you can use it like that:

json.dumps(dictionnary, cls=DatetimeEncoder) 

Here is my solution:

import json class DatetimeEncoder(json.JSONEncoder): def default(self, obj): try: return super().default(obj) except TypeError: return str(obj) 

Then you can use it like that:

json.dumps(dictionnary, cls=DatetimeEncoder) 
added 86 characters in body
Source Link
Natim
  • 18.2k
  • 25
  • 101
  • 150

Here is my solution:

# -*- coding: utf-8 -*- import json class ComplexEncoderDatetimeEncoder(json.JSONEncoder): def default(self, obj): try: return super(ComplexEncoderDatetimeEncoder, obj).default(obj) except TypeError: return str(obj) 

Then you can use it like that:

json.dumps(dictionnary, cls=DatetimeEncoder) 

Here is my solution:

# -*- coding: utf-8 -*- import json class ComplexEncoder(json.JSONEncoder): def default(self, obj): try: return super(ComplexEncoder, obj).default(obj) except TypeError: return str(obj) 

Here is my solution:

# -*- coding: utf-8 -*- import json class DatetimeEncoder(json.JSONEncoder): def default(self, obj): try: return super(DatetimeEncoder, obj).default(obj) except TypeError: return str(obj) 

Then you can use it like that:

json.dumps(dictionnary, cls=DatetimeEncoder) 
Source Link
Natim
  • 18.2k
  • 25
  • 101
  • 150
Loading