Encoding NaN in JSON

Chris Angelico rosuav at gmail.com
Wed Apr 17 21:46:37 EDT 2013


On Thu, Apr 18, 2013 at 11:39 AM, Roland Koebler <r.koebler at yahoo.de> wrote:
> as a quickhack, you
> could even monkey patch json.encoder.floatstr with a wrapper which
> returns "N/A" for NaN. (I've tested it: It works.)

Wait... you can do that? It's internal to iterencode, at least in
Python 3.3 and 2.7 that I'm looking at here. Can you share your code
please? I'd like to try that! When I first looked at the docstring, I
was thinking "Ah, can I override the bit that emits NaN to return
\"N/A\" instead?", but the code made me think that's not possible.

ChrisA



More information about the Python-list mailing list