Updated encoding of NaN to null by default

Added parameter encode_nan, which will revert to the old behavior. 
Default behavior is to encode NaN and Infinity as null. 
allow_nan is ignored.