Haoyu SUN <raptor...@gmail.com> 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 error in calculation or input data, we can use 
the allow_nan option to catch it. Database connectors such as SQLAlchemy 
translate an empty field as float('nan') for a float number field. Probably we 
can safely take it as a convention. No idea yet for representing infinity.

Once encoded, there is no way to know a null originates from NaN or None 
without additional fields.

The direct conversion from Python data types to JSON may lose part of 
information due to JSON's limited data types. When converting a BMP image to 
GIF, we have to eliminate some colors to fit in the small pallet and we do not 
expect to restore the full information BMP image has from its GIF counterpart.

I suggest we make the JSON module have at least an option to generate 
 standard-compliant JSON regardless potential loss of information, instead of 
leaving each application to have its subclass of JSONEncoder just for this 
corner case.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40633>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to