encode and decode datetime as json