More fixes for json parsing for non numeric numbers (nan and inf)

This PR adds more fixes for json parsing for double values, which is kind of scattered around the code base. An initial PR has already been merged for this issue (#1900).