Be standards compliant when dealing with JSON serialization of NaN and Inf floats

Patch by dahla