Hacker News new | ask | show | jobs
by egwor 813 days ago
I think the thing folk miss is when there’s an error like divide by zero, or the calculation would return NaN. I feel like this is the main gap/concern with using JSON and it seems to be rarely discussed.
1 comments

Agreed, this can be a pain. Python by default serialize and de-serialize the `NaN` literal, making you pay some cleanup cost once you need to interopt with other systems. (same for `Inf`)

Say what you want about NaN, but IEEE 754 is the facto way of dealing with floating points in computers and even if NaNs and Infs are a bit "fringe" it's unfortunate that the most popular serialization format can not represent these.

There are so many things that are poorly thought out or underspecified in JSON, it's amazing that it got so widely adopted for interop. No wonder that it became a perpetual source of serialization bugs.
Especially annoying given that they could have been easily adopted. Infinity could've been encoded as `1/0` (among most other possibilities). NaN could've been encoded as `0/0` (again, among most other possibilities). JSON doesn't allow all possible JavaScript literals anyway, so these encodings might have been worked if they were somehow standardized.