Forking simplejson

Amirouche Boubekki amirouche.boubekki at gmail.com
Thu Oct 27 11:24:24 EDT 2011


2011/10/27 Chris Rebert <clp2 at rebertia.com>

> On Wed, Oct 26, 2011 at 2:14 AM, Amirouche Boubekki
> <amirouche.boubekki at gmail.com> wrote:
> > Héllo,
> >
> > I would like to fork simplejson [1] and implement serialization rules
> based
> > on protocols instead of types [2], plus special cases for protocol free
> > objects, that breaks compatibility. The benefit will be a better API for
> > json serialization of custom classes and in the case of iterable it will
> > avoid a calls like:
> >
> >>>> simplejson.dumps(list(my_iterable))
> >
> > The serialization of custom objects is documented in the class instead of
> > the ``default`` function of current simplejson implementation [3].
> >
> > The encoding algorithm works with a priority list that is summarized in
> the
> > next table:
> >
> >     +-------------------+---------------+
> >     | Python protocol   | JSON          |
> >     |  or special case  |               |
> >     +===================+===============+
> <snip>
> >     | (§) unicode       | see (§)       |
> <snip>
> > (§) if the algorithm arrives here, call unicode (with proper encoding
> rule)
> > on the object and use the result as json serialization
>
> I would prefer a TypeError in such cases, for the same reason
> str.join() doesn't do an implicit str() on its operands:
> - Explicit is better than implicit.
> - (Likely) errors should never pass silently.
> - In the face of ambiguity, refuse the temptation to guess.
>

granted it's better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111027/82f30a0d/attachment-0001.html>


More information about the Python-list mailing list