Why default JSONEncoder in python cannot serialize abc.Sequence and abc.Mappings?
Question: So, if we create some class, implementing `collections.abc.MutableSequence`,
and `list` is such an example,

    
    
    class Woof(collections.MutableSequence):
        def __init__(self, data=[]):
            self.s = list(data)
        def __setitem__(self, k, v):
            self.s[k] = v
        def __getitem__(self,k):
            return self.s[k]
        def __delitem__(self,k):
            del self.s[k]
        def __repr__(self):
            return repr(self.s)
        def __len__(self):
            return len(self.s)
        def insert(self,k,v):
            self.s[k] = v
    

we cannot pass its instance to default JSONEncoder.

    
    
    >>> w = Woof(range(5,10))
    >>> json.dumps(w)
    TypeError: [5, 6, 7, 8, 9] is not JSON serializable
    

Question is not **how** to serialize custom classes, but **why** python can
serialize only its own implementations of `Sequence` and `Mapping`, but not
arbitrary ones, implementing exactly same interface.


Answer: As far as I know, Bob Ippolito (the primary author of
[`simplejson`](http://simplejson.readthedocs.org/), who also did the changes
to stdlibify it as [`json`](http://docs.python.org/library/json) in the
stdlib, and does most of the maintenance on the stdlib version) has never
given his rationale for this, so if you really wanted to know for sure, the
only thing you could do is to ask him.

But I think there's an obvious answer: If you encoded all `Sequence` types to
JSON arrays, there'd be no way to distinguish the difference `Sequence` types
at decode time. And, since your code is presumably using something other than
`list` for some reason, and some reason that the `json` module can't predict,
it may be throwing away important information.

That said, wanting to treat other sequence types—or even arbitrary
iterables—the same as `list` is a common-enough use case that it was made easy
to do if you want it, and it's [the example the docs use for
`JSONEncode.default`](https://docs.python.org/3/library/json.html#json.JSONEncoder.default).

