Improve JSON generation when NaN appears.