Serialise datetimes to JSON

Thanks for reflowing this- it's a lot easier to read!