[issue7444] Allow for a default method in the JSON decoder

Daniel Goldman report at bugs.python.org
Sat Dec 5 17:15:10 CET 2009


New submission from Daniel Goldman <goldman.inbox at gmail.com>:

I encountered JavaScript-style Date objects in a JSON document that I 
wanted to parse, and these objects were causing the Python JSON decoder 
to raise an error with a message that said "Expecting object," followed 
by the line and column numbers. Here is an example of how such an object 
appeared in the document:

"someDate": new Date(1207568200000),

I went looking in the documentation for a way to plug in a "fall-back" 
method, to be used when the module's standard conversion methods fail, 
but none of the supplied hooks seemed appropriate.

It would be enormously helpful to provide a hook for such a method in 
the JSON decoder in a future release of Python. I believe this would 
parallel the JSON encoder's "default" keyword argument. In this way, 
developers could provide their own method of handling non-standard 
values in JSON documents.

Ultimately, to parse the Date objects, I created a function similar to 
those in the json.decoder module, added the function to the 
json.decoder.ANYTHING list, and assigned a new Scanner object with this 
updated list to json.decoder.JSONScanner.

I couldn't find a similar issue in the issues list, but my apologies if 
this has already been suggested.

----------
components: Library (Lib)
messages: 95994
nosy: dhgoldman
severity: normal
status: open
title: Allow for a default method in the JSON decoder
type: feature request
versions: Python 2.7, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7444>
_______________________________________


More information about the Python-bugs-list mailing list