0

Can anyone please help me in serializing resultset returned using mysqldb in python?

I get typeerror: datetime.date(2007, 11, 15) is not JSON serializable

What is the best way to do serialize into Json object in python?

I am using json.dumps(resultset) to serialize resultset...

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Software Enthusiastic
  • 25,147
  • 16
  • 58
  • 68

3 Answers3

3

Set the "default" function passed to json.dump:

>>> d=datetime.datetime.now()
>>> json.dumps(d,default=str)
'"2009-12-18 14:22:21.405095"'
1

You can use rfc3339 strings instead:

  json.dump(datetime.now().strftime('%Y-%m-%dT%H:%M:%S'))

See: JSON datetime between Python and JavaScript

Community
  • 1
  • 1
miku
  • 181,842
  • 47
  • 306
  • 310
0

Serializing Django objects (Django Docs)

Serializing Python Objects (Dive Into Python 3)

Imran
  • 87,203
  • 23
  • 98
  • 131
czarchaic
  • 6,268
  • 29
  • 23