Just calling __str__ for Float class is not good enough solution to serialize numbers into JSON, as it ignores NaN and infinite numbers. According to ECMA-262 (NOTE4 on page 208), NaN and infinite numbers should serialize into JSON value null.
Solution: Add as_json method to Float class which checks for NaN/infinity.
Just calling
__str__
forFloat
class is not good enough solution to serialize numbers into JSON, as it ignores NaN and infinite numbers. According to ECMA-262 (NOTE4 on page 208), NaN and infinite numbers should serialize into JSON valuenull
.Solution: Add
as_json
method toFloat
class which checks for NaN/infinity.