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 all around the code base. An initial PR was opened for this problem (see #1900).