Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Encoding NaN in JSON Date: Wed, 17 Apr 2013 14:47:27 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 19 Message-ID: References: NNTP-Posting-Host: panix2.panix.com X-Trace: reader1.panix.com 1366210047 29048 166.84.1.2 (17 Apr 2013 14:47:27 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 17 Apr 2013 14:47:27 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:43764 In Miki Tebeka writes: > >> I'm trying to find a way to have json emit float('NaN') as 'N/A'. > > No. There is no way to represent NaN in JSON. It's simply not part of the > > specification. > I know that. I'm trying to emit the *string* 'N/A' for every NaN. import math x = possibly_NaN() if math.isnan(x): x = 'N/A' -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"