Encoding NaN in JSON

Chris Angelico rosuav at gmail.com
Wed Apr 17 21:41:47 EDT 2013


On Thu, Apr 18, 2013 at 11:01 AM, Miki Tebeka <miki.tebeka at gmail.com> wrote:
> [Roland]
>> yes, there is: subclass+extend the JSON-encoder, see pydoc json.
> Please read the original post before answering. What you suggested does not work since NaN is of float type.

You may be able to override a bit more of the code, though. Check out
Lib/json/encoder.py for the implementation, and have a look at the
floatstr() internal function; unfortunately you can't simply subclass
and override that, but perhaps overriding iterencode (which is where
floatstr is defined) would do the job.

ChrisA



More information about the Python-list mailing list