fixed number detection heuristics

This patch fixes multiple issues with number detection heuristics that resulted in invalid or less that optimal JSON. Numbers that have been used in string context are now correctly detected and nan/inf turned into strings.