Encoding NaN in JSON
Robert Kern
robert.kern at gmail.com
Fri Apr 19 02:13:26 EDT 2013
On 2013-04-19 10:34, Tim Roberts wrote:
> Miki Tebeka <miki.tebeka at gmail.com> wrote:
>>
>>>> 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.
>
> You understand that this will result in a chunk of text that is not JSON?
> Other JSON readers won't be able to read it.
I think he means something like this:
>>> json.dumps([float('nan')])
'["N/A"]'
Not
'[N/A]'
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list