ijl / orjson

Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy
Apache License 2.0
6.29k stars 215 forks source link

Do not deserializing to python decimal.Decimal is a nightmare for floating numbers in JSON #511

Closed wind-shift closed 3 months ago

wind-shift commented 3 months ago

Python uses floats for it's JSON library. Herein lies the problems.

$ python

import json json.dumps(10.001) '10.000999999999999' json.loads('{"blaa": 0.333331}') {u'blaa': 0.33333099999999999} type(json.loads('{"blaa": 0.333331}')['blaa']) <type 'float'>

This is unacceptable.

see https://bitcointalk.org/index.php?topic=4086.msg58882#msg58882

In fact, it’s impossible to customize the behaviour of orjson to map to decimal values. This is weird.