3 ms·
This is technically correct, except that almost all JSON libraries parse JSON numbers into either 64-bit integer or 64-bit double, so you get those lossy conver
by ludocode 7y ago
This is technically correct, except that almost all JSON libraries parse JSON numbers into either 64-bit integer or 64-bit double, so you get those lossy conversions anyway.
I've worked on a production app where we had to swap out the JSON parsing libraries in the server (Rails) and all clients (Android, iOS, Rails again) for ones that preserved numbers as BigDecimals. This was a huge pain, it made everything slower, and even then it wasn't ideal because different BigDecimal libraries aren't even necessarily compatible. Foundation's NSDecimalNumber has different limits than Android's BigDecimal for example, and these are the types used by the parsers so you can't just get the raw data to do it yourself.
If I had to do it over again I would never rely on JSON's decimal support. I'd rather stuff my decimals in strings and parse them myself.