Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-06 Thread Eric V. Smith
On 11/6/2018 6:46 AM, David Shawley wrote: On Nov 4, 2018, at 12:43 PM, Michael Selik > wrote: > If you're making a module >> > > On Sun, Nov 4, 2018, 5:49 AM David Shawley wrote: > > Personally, I would place this sort of

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-06 Thread David Shawley
On Nov 4, 2018, at 12:43 PM, Michael Selik wrote: > If you're making a module >> > > On Sun, Nov 4, 2018, 5:49 AM David Shawley > Personally, I would place this sort of serialization logic outside of the > > Standard Library -- maybe following the pattern that the rust community > > adopted on

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-05 Thread Serhiy Storchaka
06.11.18 02:17, Chris Barker via Python-ideas пише: and other nifty things -- any plans to support JSON5 in the stdlib json library? I think that would be great. When it be widely used official standard. There is a number of general data exchange formats more popular than JSON5.

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-05 Thread Chris Barker via Python-ideas
On Fri, Nov 2, 2018 at 12:17 PM, Wes Turner wrote: > JSON5 supports comments in JSON. > https://github.com/json5/json5/issues/3 > and other nifty things -- any plans to support JSON5 in the stdlib json library? I think that would be great. -CHB > ... Some form of schema is necessary to

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-04 Thread Wes Turner
Here's a JSONEncoder subclass with a default method that checks variable types in a defined sequence that includes datetime: https://gist.github.com/majgis/4200488 Passing an ordered map of (Type, fn) may or may not be any more readable than simply subclassing JSONEncoder and defining

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-03 Thread Greg Ewing
David Shawley wrote: I'm +1 on adding support for serializing datetime.date and datetime.datetime *but* I'm -1 on automatically deserializing anything that looks like a ISO-8601 in json.load*. The asymmetry is the only thing that kept me from bringing this up previously. This asymmetry

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-03 Thread Chris Angelico
On Sun, Nov 4, 2018 at 1:00 AM David Shawley wrote: > Very good point. The JSON document type only supports object literals, > numbers, strings, and Boolean literals. My suggestion was specifically to > provide an extensible mechanism for encoding arbitrary objects into the > supported

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-03 Thread Wes Turner
jsondate, for example, supports both .load[s]() and .dump[s](); but only for UTC datetimes https://github.com/rconradharris/jsondate/blob/master/jsondate/__init__.py UTC is only sometimes a fair assumption; otherwise it's dangerous to assume that timezone-naieve [ISO8601] strings represent UTC-0

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-03 Thread David Shawley
On Nov 3, 2018, at 9:29 AM, Chris Angelico wrote: > > I think we need to clarify an important distinction here. JSON, as a > format, does *not* support date/time objects in any way. But > JavaScript's JSON.stringify() function is happy to accept them, and > will represent them as strings. >

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-03 Thread Serhiy Storchaka
02.11.18 19:26, Chris Barker via Python-ideas пише: On Fri, Nov 2, 2018 at 9:31 AM, M.-A. Lemburg > wrote: Serialization of those data types is not defined in the JSON standard: https://www.json.org/ That being said, ISO 8601 is a standard for datetime

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-03 Thread Chris Angelico
On Sun, Nov 4, 2018 at 12:02 AM David Shawley wrote: > > On Nov 2, 2018, at 12:28 PM, Calvin Spealman wrote: > > > 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

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-03 Thread David Shawley
On Nov 2, 2018, at 12:28 PM, Calvin Spealman wrote: > 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

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-02 Thread Wes Turner
JSON-LD supports datetimes (as e.g. IS8601 xsd:datetimes) https://www.w3.org/TR/json-ld11/#typed-values Jsonpickle (Python, JS, ) supports datetimes, numpy arrays, pandas dataframes https://github.com/jsonpickle/jsonpickle JSON5 supports comments in JSON. https://github.com/json5/json5/issues/3

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-02 Thread Michael Selik
On Fri, Nov 2, 2018 at 10:31 AM Philip Martin wrote: > [Why don't] csv writer and DictWriter provide ... > serialization/deserialization hooks? > Do you have a specific use-case in mind? My intuition is that comprehensions provide sufficient functionality such that changing the csv module

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-02 Thread Philip Martin
My bad. I think I need to clarify my objective. I definitely understand the issues regarding serialization/deserialization on JSON, i.e. decimals as strings, etc., and hooking in a default serializer function is easy enough. I guess my question is more related to why the csv writer and DictWriter

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-02 Thread Chris Barker via Python-ideas
On Fri, Nov 2, 2018 at 9:31 AM, M.-A. Lemburg wrote: > Serialization of those data types is not defined in the JSON standard: > > https://www.json.org/ That being said, ISO 8601 is a standard for datetime stamps, and a defacto one for JSON So building encoding of datetime into Python's json

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-02 Thread M.-A. Lemburg
Serialization of those data types is not defined in the JSON standard: https://www.json.org/ so you have to extend the parser/serializers to support them. On 02.11.2018 17:19, Philip Martin wrote: > Is there any reason why date, datetime, and UUID objects automatically > serialize to default

Re: [Python-ideas] Serialization of CSV vs. JSON

2018-11-02 Thread Calvin Spealman
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

[Python-ideas] Serialization of CSV vs. JSON

2018-11-02 Thread Philip Martin
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)