This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Haoyu SUN
Recipients Haoyu SUN, eric.smith, mark.dickinson, rhettinger
Date 2020-05-16.13:13:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1589634815.26.0.176497914642.issue40633@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-05-16 13:13:35Haoyu SUNsetrecipients: + Haoyu SUN, rhettinger, mark.dickinson, eric.smith
2020-05-16 13:13:35Haoyu SUNsetmessageid: <1589634815.26.0.176497914642.issue40633@roundup.psfhosted.org>
2020-05-16 13:13:35Haoyu SUNlinkissue40633 messages
2020-05-16 13:13:35Haoyu SUNcreate