silently convert inf and NaN values to null

Hi,

Recently had an issue where Inf and NaN values were being put into our JSON strings. Inf and Nan values are not valid JSON. This patch will convert them to null objects.
If users want, it might be an idea to have an #ifdef to convert them to strings instead.

Thanks,
Mark