Re: Encoding NaN in JSON

2013-04-22 Thread Wayne Werner
On Sat, 20 Apr 2013, Chris “Kwpolska” Warrick wrote: On Fri, Apr 19, 2013 at 9:42 PM, Grant Edwards wrote: The OP asked for a string, and I thought you were proposing the string 'null'. If one is to use a string, then 'NaN' makes the most sense, since it can be converted back into a floating

Re: Encoding NaN in JSON

2013-04-20 Thread Chris “Kwpolska” Warrick
On Fri, Apr 19, 2013 at 9:42 PM, Grant Edwards wrote: > The OP asked for a string, and I thought you were proposing the string > 'null'. If one is to use a string, then 'NaN' makes the most sense, > since it can be converted back into a floating point NaN object. > > I infer that you were proposi

Re: Encoding NaN in JSON

2013-04-19 Thread Miki Tebeka
> > You understand that this will result in a chunk of text that is not JSON? > I think he means something like this: > >>> json.dumps([float('nan')]) > '["N/A"]' That's exactly what I mean :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-19 Thread Grant Edwards
On 2013-04-19, Chris ???Kwpolska??? Warrick wrote: > On Fri, Apr 19, 2013 at 4:54 PM, Grant Edwards > wrote: >> On 2013-04-18, Wayne Werner wrote: >>> On Wed, 17 Apr 2013, Miki Tebeka wrote: >>> >> I'm trying to find a way to have json emit float('NaN') as 'N/A'. > No. There is no way

Re: Encoding NaN in JSON

2013-04-19 Thread Chris “Kwpolska” Warrick
On Fri, Apr 19, 2013 at 4:54 PM, Grant Edwards wrote: > On 2013-04-18, Wayne Werner wrote: >> On Wed, 17 Apr 2013, Miki Tebeka 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 sp

Re: Encoding NaN in JSON

2013-04-19 Thread Grant Edwards
On 2013-04-18, Wayne Werner wrote: > On Wed, 17 Apr 2013, Miki Tebeka 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* '

Re: Encoding NaN in JSON

2013-04-18 Thread Robert Kern
On 2013-04-19 10:34, Tim Roberts wrote: Miki Tebeka 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 un

Re: Encoding NaN in JSON

2013-04-18 Thread Tim Roberts
Miki Tebeka 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

Re: Encoding NaN in JSON

2013-04-18 Thread Wayne Werner
On Wed, 17 Apr 2013, Miki Tebeka 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. Why not use `null` instead? I

Re: Encoding NaN in JSON

2013-04-18 Thread Roland Koebler
On Thu, Apr 18, 2013 at 11:46:37AM +1000, Chris Angelico wrote: > 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. In Python 2.6 it wasn't internal to iterencode; in Python 2.7 and 3.x you probably would have to monkey-patch iterencode

Re: Encoding NaN in JSON

2013-04-17 Thread Chris Angelico
On Thu, Apr 18, 2013 at 11:39 AM, Roland Koebler 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 loo

Re: Encoding NaN in JSON

2013-04-17 Thread Chris Angelico
On Thu, Apr 18, 2013 at 11:01 AM, Miki Tebeka 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,

Re: Encoding NaN in JSON

2013-04-17 Thread Roland Koebler
Hi, > > 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. ok, right, default does not work this way. But I would still suggest to extend the JSON-encoder, since that is

Re: Encoding NaN in JSON

2013-04-17 Thread Miki Tebeka
[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. -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-17 Thread Roland Koebler
Hi, > > Easiest way is probably to transform your object before you try to write > Yeah, that's what I ended up doing. Wondered if there's a better way ... yes, there is: subclass+extend the JSON-encoder, see pydoc json. e.g.: class JsonNanEncoder(json.JSONEncoder): def default(self, obj):

Re: Encoding NaN in JSON

2013-04-17 Thread Dave Angel
On 04/17/2013 03:05 PM, Johann Hibschman wrote: 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.

Re: Encoding NaN in JSON

2013-04-17 Thread Miki Tebeka
> >>> I'm trying to find a way to have json emit float('NaN') as 'N/A'. > Easiest way is probably to transform your object before you try to write Yeah, that's what I ended up doing. Wondered if there's a better way ... Thanks, -- Miki -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-17 Thread Johann Hibschman
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. Easiest way is probably to transform your

Re: Encoding NaN in JSON

2013-04-17 Thread John Gordon
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()

Re: Encoding NaN in JSON

2013-04-17 Thread Miki Tebeka
>> 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. -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-16 Thread Tim Roberts
Miki Tebeka wrote: > >I'm trying to find a way to have json emit float('NaN') as 'N/A'. >I can't seem to find a way since NaN is a float, which means overriding >"default" won't help. > >Any simple way to do this? No. There is no way to represent NaN in JSON. It's simply not part of the specif

Encoding NaN in JSON

2013-04-16 Thread Miki Tebeka
Greetings, I'm trying to find a way to have json emit float('NaN') as 'N/A'. I can't seem to find a way since NaN is a float, which means overriding "default" won't help. Any simple way to do this? Thanks, -- Miki -- http://mail.python.org/mailman/listinfo/python-list