Forking simplejson
Chris Rebert
clp2 at rebertia.com
Thu Oct 27 10:16:46 EDT 2011
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.
Cheers,
Chris
--
http://rebertia.com
More information about the Python-list
mailing list