[issue40633] json.dumps() should encode float number NaN to null

2020-12-30 Thread Mark Dickinson
Mark Dickinson added the comment: > RFC 8259 (current RFC for JSON): https://tools.ietf.org/html/rfc7159 Argh; copy-and-paste fail. That link should have been https://tools.ietf.org/html/rfc8259, of course. -- ___ Python tracker

[issue40633] json.dumps() should encode float number NaN to null

2020-12-30 Thread Mark Dickinson
Mark Dickinson added the comment: For the record, some helpful resources: ECMA-404 (the ECMA standardization of JSON): http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf RFC 8259 (current RFC for JSON): https://tools.ietf.org/html/rfc7159. (I mistakenly referred to RF

[issue40633] json.dumps() should encode float number NaN to null

2020-12-30 Thread Mark Dickinson
Mark Dickinson added the comment: @Luca: you might want to open a new feature request issue; it's not clear to me what exact behaviour change you're proposing for Python. What was rejected in this issue was the proposal to *automatically* convert NaNs and infinities to nulls by default, but

[issue40633] json.dumps() should encode float number NaN to null

2020-12-29 Thread Luca Barba
Luca Barba added the comment: I agree with arjanstaring This implementation is not standard compliant and breaks interoperability with every ECMA compliant Javascript deserializer. Technically is awful of course but interoperability and standardization come before than technical cleanliness

[issue40633] json.dumps() should encode float number NaN to null

2020-11-20 Thread Mark Dickinson
Mark Dickinson added the comment: @Arjan Staring: could you point to which part of the JSON specification you're looking at? At https://tools.ietf.org/html/rfc7159, the only reference to NaNs that I see is: > Numeric values that cannot be represented in the grammar below (such > as Infinity

[issue40633] json.dumps() should encode float number NaN to null

2020-11-20 Thread Arjan Staring
Arjan Staring added the comment: Please re-evaluate; the current behaviour is incompatible with JSON specification in favour of providing the user/application/consumer of the resulted JSON information regarding the conversion process. Given what is stated in the documentation I do agree with

[issue40633] json.dumps() should encode float number NaN to null

2020-05-18 Thread Mark Dickinson
Mark Dickinson added the comment: Agreed; closing. -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracker ___ __

[issue40633] json.dumps() should encode float number NaN to null

2020-05-18 Thread Eric V. Smith
Eric V. Smith added the comment: I think it should be closed. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue40633] json.dumps() should encode float number NaN to null

2020-05-18 Thread Mark Dickinson
Mark Dickinson added the comment: > We could add an option to cause NaNs to raise an error, but I don't think it > would get used. If that option were extended to also cause infinities to raise an error, then I'd use it. We have code that's producing JSON without knowing in advance exactly

[issue40633] json.dumps() should encode float number NaN to null

2020-05-17 Thread Raymond Hettinger
Raymond Hettinger added the comment: I missed that as well ;-) Shall we close this now? -- ___ Python tracker ___ ___ Python-bugs-

[issue40633] json.dumps() should encode float number NaN to null

2020-05-17 Thread Mark Dickinson
Mark Dickinson added the comment: ... but I'm an idiot, since that option is already there (allow_nan=False), and I've just checked that we are in fact using it. -- ___ Python tracker __

[issue40633] json.dumps() should encode float number NaN to null

2020-05-17 Thread Raymond Hettinger
Raymond Hettinger added the comment: We could add an option to cause NaNs to raise an error, but I don't think it would get used. Otherwise, it's likely best to leave the module as-is. -- ___ Python tracker __

[issue40633] json.dumps() should encode float number NaN to null

2020-05-16 Thread Eric V. Smith
Eric V. Smith added the comment: I don't think we want to generate output no matter what. Should datetime instances become null instead of raising an exception? Are there types other than float where some values are json serializable and others aren't? -- __

[issue40633] json.dumps() should encode float number NaN to null

2020-05-16 Thread Haoyu SUN
Haoyu SUN added the comment: About using null in JSON to represnet NaN value of a float type, I prefer this logic: float is a numeric type that expecting a number as its value, "Not a Number" on a numeric type is equivalent to None (¬Number ∩ NumericValues = Empty). If we need to capture an e

[issue40633] json.dumps() should encode float number NaN to null

2020-05-15 Thread Raymond Hettinger
Raymond Hettinger added the comment: One other issue just came to mind. While we could convert NaN to null during encoding, there isn't a reasonable way to reverse the process (a null could either be a NaN or a legitimate None). That would limit the utility of a new optional conversion. -

[issue40633] json.dumps() should encode float number NaN to null

2020-05-15 Thread Raymond Hettinger
Raymond Hettinger added the comment: [Eric] > this is documented behavior [Mark] > I definitely wouldn't want to see nans translated to > "null" by default. I concur with both of these statements. I would support adding an option (off by default) to convert NaNs to None. While NaNs were o

[issue40633] json.dumps() should encode float number NaN to null

2020-05-15 Thread Mark Dickinson
Mark Dickinson added the comment: I don't think "null" in JSON is supposed to represent "Not a Number"; it's closer in meaning to Python's `None`. I definitely wouldn't want to see nans translated to "null" by default. This also only seems to address a part of the issue: what's the proposed

[issue40633] json.dumps() should encode float number NaN to null

2020-05-15 Thread Eric V. Smith
Eric V. Smith added the comment: I think that's reasonable, although I could see someone objecting ("just use simplejson instead"). I suggest discussing this on the python-ideas mailing list and see what people think over there. It might help to create a PR first, if it's not a lot of work.

[issue40633] json.dumps() should encode float number NaN to null

2020-05-15 Thread Haoyu SUN
Haoyu SUN added the comment: Thank you for the timely reply, Eric. How about we add an optional argument (like the argument "ignore_nan" defaults to False as the package simplejson does) to functions like json.dumps(). So that user can choose whether he needs NaN encoded as NaN or null, mean

[issue40633] json.dumps() should encode float number NaN to null

2020-05-15 Thread Eric V. Smith
Eric V. Smith added the comment: Since this is documented behavior (https://docs.python.org/3.8/library/json.html#infinite-and-nan-number-values), we can't change it by default without breaking code. What JavaScript JSON encoders and decoders specifically have a problem with this behavior?

[issue40633] json.dumps() should encode float number NaN to null

2020-05-15 Thread Haoyu SUN
New submission from Haoyu SUN : Float numbers in Python can have 3 special number: nan, inf, -inf, which are encoded by json module as "NaN", "Infinity", "-Infinity". These representations are not compatible with JSON specifications RFC7159: https://tools.ietf.org/html/rfc7159.html#page-6 The