[Python-ideas] Serialization of CSV vs. JSON

Calvin Spealman cspealma at redhat.com
Fri Nov 2 12:28:18 EDT 2018


First, this list is not appropriate. You should ask such a question in
python-list.

Second, JSON is a specific serialization format that explicitly rejects
datetime objects in *all* the languages with JSON libraries. You can only
use date objects in JSON if you control or understand both serialization
and deserialization ends and have an agreed representation.

On Fri, Nov 2, 2018 at 12:20 PM Philip Martin <philip.martin2007 at gmail.com>
wrote:

> Is there any reason why date, datetime, and UUID objects automatically
> serialize to default strings using the csv module, but json.dumps throws an
> error as a default? i.e.
>
> import csv
> import json
> import io
> from datetime import date
>
> stream = io.StringIO()
> writer = csv.writer(stream)
> writer.writerow([date(2018, 11, 2)])
> # versus
> json.dumps(date(2018, 11, 2))
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181102/50fb7bbc/attachment.html>


More information about the Python-ideas mailing list